Backend¶
discord_http.backend module¶
- class discord_http.backend.DiscordHTTP(*, client)¶
Bases:
ApplicationServes as the fundamental HTTP server for Discord Interactions.
We recommend to not touch this class, unless you know what you’re doing
- Parameters:
client (Client)
- verify_key: Ed25519PublicKey | None¶
The verify key used to validate incoming requests, if not set, it will try to fetch from the bot’s public key.
- async handle_gateway_interaction(data, *, replayed=False) None¶
Handles an interaction received over the gateway, used when the application has no interactions endpoint URL.
It runs the exact same way as an HTTP interaction, but the response is sent to Discord’s callback endpoint instead of being the HTTP response body.
- ATTRS = frozenset({'_cleanup_ctx', '_client_max_fields', '_client_max_size', '_debug', '_frozen', '_handler_args', '_has_legacy_middlewares', '_loop', '_middlewares', '_middlewares_handlers', '_on_cleanup', '_on_response_prepare', '_on_shutdown', '_on_startup', '_pre_frozen', '_router', '_run_middlewares', '_state', '_subapps', 'logger'})¶
- add_domain(domain, subapp) MatchedSubAppResource¶
- Return type:
MatchedSubAppResource- Parameters:
domain (str)
subapp (Application)
- add_subapp(prefix, subapp) PrefixedSubAppResource¶
- Return type:
PrefixedSubAppResource- Parameters:
prefix (str)
subapp (Application)
- property cleanup_ctx: CleanupContext¶
- clear() None. Remove all items from D.¶
- items() a set-like object providing a view on D's items¶
- keys() a set-like object providing a view on D's keys¶
- property loop: AbstractEventLoop¶
- make_handler(*, loop=None, access_log_class=<class 'aiohttp.web_log.AccessLogger'>, **kwargs) Server¶
- Return type:
Server- Parameters:
loop (AbstractEventLoop | None)
access_log_class (type[AbstractAccessLogger])
kwargs (Any)
- property middlewares: FrozenList¶
- property on_cleanup: Signal¶
- property on_response_prepare: Signal¶
- property on_shutdown: Signal¶
- property on_startup: Signal¶
- pop(k[, d]) v, remove specified key and return the corresponding value.¶
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair¶
as a 2-tuple; but raise KeyError if D is empty.
- property router: UrlDispatcher¶
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D¶
- async startup() None¶
Causes on_startup signal
Should be called in the event loop along with the request handler.
- Return type:
- update([E, ]**F) None. Update D from mapping/iterable E and F.¶
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values¶
- error_messages(ctx, e) MessageResponse | None¶
Used to return error messages to Discord.
By default, it will only cover CheckFailed errors. You can overwrite this function to return your own error messages.
- Parameters:
- Return type:
- Returns:
The message response provided by the library error handler
- async index_ping(_request) Response¶
Used to ping the interaction url, to check if it’s working.
You can overwrite this function to return your own data as well. Remember that it must return dict
- Return type:
Response- Parameters:
_request (Request)
- jsonify(data, *, status=200) Response¶
Respond with JSON data in a standardized way using orjson.
Serves as the replacement for aiohttp’s built-in json response.
- multipart_response(body, *, status=200) Response¶
Respond to an interaction in a standardized way.
- Parameters:
body (
BaseResponse|None) – The body to respond withstatus (
int) – The status code to respond with
- Return type:
Response- Returns:
The response object