Http

Warning

This module is not meant to be used directly, it is used internally by discord_http.Client.

discord_http.http module

class discord_http.http.DiscordAPI(*, client)

Bases: object

Parameters:

client (Client)

create_jitter() float

Simply returns a random float between 0 and 1.

Return type:

float

async fetch_commands(guild_id=None) dict

Fetches the commands for the bot.

Parameters:

guild_id (int | None) – The guild ID to fetch the commands for (if None, commands will be global)

Return type:

dict

Returns:

The response from the request

Raises:

HTTPException – If the request returned anything other than 200. Typically this means the guild is not found.

get_ratelimit(key) Ratelimit

Get a ratelimit object from the bucket.

Return type:

Ratelimit

Parameters:

key (str)

async me() UserClient

Fetches the bot’s user information.

Return type:

UserClient

Returns:

The bot’s user object

Raises:

RuntimeError

  • If the bot token is not valid - If the bot is not allowed to use the some intents

async query(method, path, *, res_method='json', retry_codes=None, **kwargs) HTTPResponse

Make a request to the Discord API.

Parameters:
  • method (Literal['GET', 'POST', 'DELETE', 'PUT', 'HEAD', 'PATCH', 'OPTIONS']) – Which HTTP method to use

  • path (str) – The path to make the request to

  • res_method (Literal['text', 'read', 'json']) – The method to use to get the response

  • retry_codes (list[int] | None) – The HTTP codes to retry regardless of the response

  • **kwargs – The keyword arguments to pass to the aiohttp.ClientSession.request method

Return type:

HTTPResponse

Returns:

The response from the request

Raises:
async update_commands(data, guild_id=None) dict

Updates the commands for the bot.

Parameters:
  • data (list[dict] | dict) – The JSON data to send to Discord API

  • guild_id (int | None) – The guild ID to update the commands for (if None, commands will be global)

Return type:

dict

Returns:

The response from the request

class discord_http.http.HTTPResponse(*, status, response, reason, res_method, headers)

Bases: Generic[ResponseT]

Parameters:
  • status (int)

  • response (ResponseT)

  • reason (str | None)

  • res_method (Literal['text', 'read', 'json'])

  • headers (CIMultiDictProxy[str])