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(*, token: str, application_id: int | None, api_version: int | None = None)[source]

Bases: object

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

Fetches the commands for the bot

Parameters:

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

Returns:

The response from the request

Return type:

dict

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

User: Fetches the bot’s user information

async query(method: Literal['GET', 'POST', 'DELETE', 'PUT', 'HEAD', 'PATCH', 'OPTIONS'], path: str, *, res_method: Literal['json'] = 'json', **kwargs) HTTPResponse[dict[Any, Any]][source]
async query(method: Literal['GET', 'POST', 'DELETE', 'PUT', 'HEAD', 'PATCH', 'OPTIONS'], path: str, *, res_method: Literal['read'] = 'read', **kwargs) HTTPResponse[bytes]
async query(method: Literal['GET', 'POST', 'DELETE', 'PUT', 'HEAD', 'PATCH', 'OPTIONS'], path: str, *, res_method: Literal['text'] = 'text', **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

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 (Optional[int]) – 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, res_method: Literal['text', 'read', 'json'], headers: dict[str, str])[source]

Bases: Generic[ResponseT]