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:
objectThe main class for interacting with the Discord API.
- Parameters:
client (Client)
- bot: Client¶
A reference to the client’s cache for easy access within HTTP methods.
- Type:
The client instance that owns this HTTP client. cache
- base_url¶
The base URL for the Discord API.
- http: HTTPClient¶
The HTTP client used to make requests to the Discord API.
- get_ratelimit(key) Ratelimit¶
Get a ratelimit object from the bucket.
- Parameters:
key (
str) – The key to get the ratelimit for- Return type:
Ratelimit- Returns:
The ratelimit object for the given key
- 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 usepath (
str) – The path to make the request tores_method (
Literal['text','read','json']) – The method to use to get the responseretry_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:
- Returns:
The response from the request
- 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 me() Application¶
Fetches the bot’s user information.
- Return type:
- Returns:
The bot’s user object
- Raises:
If the bot token is not valid - If the bot is not allowed to use the some intents
- 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:
- Returns:
The response from the request
- Raises:
HTTPException – If the request returned anything other than 200. Typically this means the guild is not found.
- class discord_http.http.HTTPResponse(*, status, response, reason, res_method, headers)¶
Bases:
Generic[ResponseT]Represents a response from the HTTP request.
- Parameters:
- status¶
The HTTP status code of the response.
- response¶
The response data, which can be of type str, bytes, or dict depending on the request.
- res_method¶
The method used to retrieve the response data.
- reason¶
The reason phrase returned by the server, if any.
- headers¶
The headers of the response, as a CIMultiDictProxy.