# Welcome

Thanks for using Discords.com. This will be your guide while you navigate our API.

## Need help with our API?

We have an [API support channel](https://discord.gg/dsl) in our bot server.


# Users

## User

<mark style="color:blue;">`GET`</mark> `https://discords.com/bots/api/user/:id`

#### Path Parameters

| Name | Type    | Description                                              |
| ---- | ------- | -------------------------------------------------------- |
| id   | integer | The ID of the user you are requesting information about. |

{% tabs %}
{% tab title="200 The server has located the users information and displayed it." %}

```
The content of this response varies.
```

{% endtab %}

{% tab title="404 The user you are requesting does not exist on the website." %}

```javascript
{ message: 'User not found.' }
```

{% endtab %}
{% endtabs %}

## Bots

<mark style="color:blue;">`GET`</mark> `https://discords.com/bots/api/user/:id/bots`

#### Path Parameters

| Name | Type    | Description                                              |
| ---- | ------- | -------------------------------------------------------- |
| id   | integer | The ID of the user you are requesting information about. |

{% tabs %}
{% tab title="200 The server has located information about the user's bots and displayed it." %}

```
The content of this response varies.
```

{% endtab %}

{% tab title="404 You may receive of the following 404 errors depending on your situation." %}

```javascript
//The user you are requesting does not exist on the website:
{ message: 'User not found.' }

//The user you are requesting does not own any bots on the website:
{ bots: 'User has no bots.' }
```

{% endtab %}
{% endtabs %}


# Bots

## Bot

<mark style="color:blue;">`GET`</mark> `https://discords.com/bots/api/bot/:id`

#### Path Parameters

| Name | Type    | Description                                             |
| ---- | ------- | ------------------------------------------------------- |
| id   | integer | The ID of the bot you are requesting information about. |

{% tabs %}
{% tab title="200 The website was successfully able to fetch information about the bot." %}

```
The content of this response varies.
```

{% endtab %}

{% tab title="404 The bot you requested is not listed on the website." %}

```javascript
{"message":"Bot not found."}
```

{% endtab %}
{% endtabs %}

## Votes

<mark style="color:blue;">`GET`</mark> `https://discords.com/bots/api/bot/:id/votes`

#### Path Parameters

| Name | Type    | Description                                                 |
| ---- | ------- | ----------------------------------------------------------- |
| id   | integer | The ID of the bot you are requesting voting information on. |

#### Headers

| Name          | Type   | Description                            |
| ------------- | ------ | -------------------------------------- |
| Authorization | string | The bot's API token.                   |
| Content-Type  | string | This should be set to application/json |

{% tabs %}
{% tab title="200 The website was successfully able to fetch information about the bot." %}

```
{
    "hasVoted": [],
    "hasVoted24": [],
    "votes": 0,
    "votes24": 0,
    "votesMonth": 0
}
```

{% endtab %}

{% tab title="400 You provided the wrong API token for the bot." %}

```
{"message":"Invalid authorization token."}
```

{% endtab %}

{% tab title="404 The bot you requested is not listed on the website." %}

```
{"message":"Bot not found."}
```

{% endtab %}
{% endtabs %}

## Widget

<mark style="color:blue;">`GET`</mark> `https://discords.com/bots/api/bot/:id/widget`

#### Path Parameters

| Name | Type    | Description                                          |
| ---- | ------- | ---------------------------------------------------- |
| id   | integer | The ID of the bot you are requesting information on. |

#### Query Parameters

| Name  | Type   | Description                               |
| ----- | ------ | ----------------------------------------- |
| theme | string | Set this to dark for a dark themed widget |
| width | number | Set the width of the widget               |

{% tabs %}
{% tab title="200 The website was successfully able to fetch and display the bot's widget." %}

```
The content of this response varies.
```

{% endtab %}

{% tab title="404 The bot you requested is not listed on the website." %}

```javascript
{"message":"Bot not found."}
```

{% endtab %}
{% endtabs %}

## Server Count

<mark style="color:green;">`POST`</mark> `https://discords.com/bots/api/bot/:id`

#### Path Parameters

| Name | Type    | Description                                          |
| ---- | ------- | ---------------------------------------------------- |
| id   | integer | The ID of the bot you are posting information about. |

#### Headers

| Name          | Type   | Description          |
| ------------- | ------ | -------------------- |
| Authorization | string | The bot's API token. |

#### Request Body

| Name          | Type   | Description                   |
| ------------- | ------ | ----------------------------- |
| server\_count | number | The server count for the bot. |

{% tabs %}
{% tab title="200 Server count was successfully received and updated." %}

```javascript
{ message: 'Server count successfully updated.' }
```

{% endtab %}

{% tab title="400 You may receive one of the following 400 errors depending on your situation." %}

```javascript
//You did not provide any bot token:
{ message: 'Authorization is required.' }

//You did not provide any server count:
{ message: 'Server count is required.' }

//The server count you provided was not a valid number:
{ message: 'Server count must be a valid number.' }

//The token you provided does not match the bot's token:
{ message: 'Invalid authorization token.' }
```

{% endtab %}

{% tab title="404 The bot you are trying to post information on is not listed." %}

```javascript
{ message: 'Invalid bot.' }
```

{% endtab %}
{% endtabs %}


# Receiving Votes

## Receive Vote

<mark style="color:green;">`POST`</mark> `​https://your.webhook.com/discordswebhook`

We recomend you end your webhooks with `/discordswebhook`, although it's not required.

#### Headers

| Name          | Type   | Description                                                                        |
| ------------- | ------ | ---------------------------------------------------------------------------------- |
| Authorization | string | The plain text string used to verifiy that the request is coming from discords.com |

#### Request Body

| Name  | Type   | Description                                                                                                                                                      |
| ----- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| user  | string | The ID of the user who voted                                                                                                                                     |
| bot   | string | The ID of the bot which recieved the vote                                                                                                                        |
| votes | string | Contains totalVotes, votesMonth, votes24, hasVoted - a list of IDs of users who have voted this month, and Voted24 - a list of IDs of users who have voted today |
| type  | string | The type of event, whether it is a vote event or test event                                                                                                      |

{% tabs %}
{% tab title="200 " %}

```
// No response is required but a simple OK would be nice
```

{% endtab %}
{% endtabs %}


# Python

A simple Python API wrapper

## Notice

This wrapper is intended to function within a discord.py client object and will not function correctly outside of one. More features and functionality will be added going forward

## Installation

```
pip install discordspy
```

The project's github can be found [here](https://github.com/judev1/discordspy), while it's pypi page can be found [here](https://pypi.org/project/discordspy/)

## Features

* Server count posting
* Built-in automatic & interval server count posting
* Built-in voting webhook handler
* Voting & server posting events

## Examples

### Auto posting servers

Auto posting posts the server count whenever the bot is added to/removed from a server, while still abiding with our ratelimits. This example also includes an on server post event.

```python
from discord.ext import commands
import discordspy

bot = commands.Bot("!")
discords = discordspy.Client(bot, DISCORDS_TOKEN, post=discordspy.Post.auto())

@bot.event
async def on_discords_server_post(status):
    if status == 200:
        print("Posted the server count:", discords.servers())

bot.run(TOKEN)
```

### Interval posting servers

Interval posting posts the server count at regular specified intervals, by default it is set to 30 minutes. This example also includes an on server post event.

```python
from discord.ext import commands
import discordspy

bot = commands.Bot("!")
post = discordspy.Post.interval(minutes=30, hours=1)
discords = discordspy.Client(bot, DISCORDS_TOKEN, post=post)

@bot.event
async def on_discords_server_post(status):
    if status == 200:
        print("Posted the server count:", discords.servers())

bot.run(TOKEN)
```

### Webhook voting event

Setting up webhooks, along with an event to recieve them

**IMPORTANT:** Your webhook url must end with `/discordswebhook` if you wish to use a different path, please specify it using the path argument inside the webhook method `path="/customwebhook"`,

**IMPORTANT:** To recieve webhooks you must have set up port forwarding and specified the port in the webhook section on your bot page, by default the port is `8080`

```python
from discord.ext import commands
import discordspy

bot = commands.Bot("!")
discords = discordspy.Client(bot, DISCORDS_TOKEN)
discords.webhook(port=6969, auth="password")

@bot.event
async def on_discords_vote(data):
    print("Recieved a vote")

bot.run(TOKEN)
```

### Cog example

Using all the features within a cog

```python
from discord.ext import commands
import discordspy

class discords_cog(commands.Cog):

    def __init__(self, bot):
        self.discords = discordspy.Client(bot, DISCORDS_TOKEN)
        self.discords.webhook(port=6969, auth="password")
    
    @commands.command()
    def postservers(self, ctx):
        self.discords.post_servers()

    @commands.Cog.listener()
    async def on_discords_server_post(self, status):
        log_channel = self.bot.get_channel(LOG_CHANNEL_ID)
        if status == 200:
            await log_channel.send("Posted the server count")
        else:
            await log_channel.send("Failed to post the server count")

    @commands.Cog.listener()
    async def on_discords_vote(self, data):
        print("Recieved a vote")

def setup(bot):
    bot.add_cog(discords_cog(bot))
```


# Documentation

## *`discordspy.`***`Client(bot, token, post=None)`**

Creates a discordspy client object to communicate discords.com API.

### **Paramaters**

* `bot` - A discord.Client object.
* `token` - Your bot's discords.com API token.
* `post` - A discordspy post object.

### **Methods**

#### `servers()`

> Returns the number of servers the client is in.
>
> **Returns**
>
> * `server_count`

#### `post_servers()`

> A method to post the number of server the client is in, cancels if the client is being ratelimited and a newer request is available.

#### `webhook(port=None, auth="", path="/discordswebhook")`

> A method to post the number of server the client is in, cancels if the client is being ratelimited and a newer request is available.
>
> **Paramaters**
>
> * `port` - The port that the client should listen to webhooks on, can't be in use. The default port is 8080.
> * `auth` - The plain text string used to verify that the request is coming from discords.com.
> * `path` - The path the webhook should be sent to.

## *`discordspy.`***`Post`**

A non callable class to create post objects for posting stats

### **Methods**

#### `auto()`

> Returns&#x20;
>
> **Returns**
>
> * `<auto posting PostObject>`

#### `interval(seconds=0, minutes=0, hours=0)`

> Returns a PostObject to post stats at certain intervals, by default this is set to 30 minutes.
>
> **Parameters**
>
> * `seconds` - part of the duration of the interval in seconds.
> * `minutes` - part of the duration of the interval in minutes
> * `hours` - part od the duration of the interval in hours
>
> **Returns**
>
> * `<interval posting PostObject>`


