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: Client)[source]

Bases: object

create_jitter() float[source]

float: Simply returns a random float between 0 and 1

async fetch_commands(guild_id: int | None = None) dict[source]

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)

Returns:

The response from the request

Return type:

dict

Raises:

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

get_ratelimit(key: str) Ratelimit[source]
async me() UserClient[source]

User: Fetches the bot’s user information

Returns:

The bot’s user object

Return type:

User

Raises:

RuntimeError

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

async query(method: Literal['GET', 'POST', 'DELETE', 'PUT', 'HEAD', 'PATCH', 'OPTIONS'], path: str, *, res_method: Literal['json'] = 'json', retry_codes: list[int] | None = None, **kwargs) HTTPResponse[dict[Any, Any]][source]
async query(method: Literal['GET', 'POST', 'DELETE', 'PUT', 'HEAD', 'PATCH', 'OPTIONS'], path: str, *, res_method: Literal['read'] = 'read', retry_codes: list[int] | None = None, **kwargs) HTTPResponse[bytes]
async query(method: Literal['GET', 'POST', 'DELETE', 'PUT', 'HEAD', 'PATCH', 'OPTIONS'], path: str, *, res_method: Literal['text'] = 'text', retry_codes: list[int] | None = None, **kwargs) HTTPResponse[str]

Make a request to the Discord API

Parameters:
  • method (str) – Which HTTP method to use

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

  • res_method (str) – The method to use to get the response

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

Returns:

The response from the request

Return type:

HTTPResponse

Raises:
  • ValueError – Invalid HTTP method

  • DiscordServerError – Something went wrong on Discord’s end

  • Forbidden – You are not allowed to do this

  • NotFound – The resource was not found

  • HTTPException – Something went wrong

  • RuntimeError – Unreachable code, reached max tries (5)

async update_commands(data: list[dict] | dict, guild_id: int | None = None) dict[source]

Updates the commands for the bot

Parameters:
  • data (list[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)

Returns:

The response from the request

Return type:

dict

class discord_http.http.HTTPResponse(*, status: int, response: ResponseT, reason: str | None, res_method: Literal['text', 'read', 'json'], headers: CIMultiDictProxy[str])[source]

Bases: Generic[ResponseT]