Backend

discord_http.backend module

class discord_http.backend.DiscordHTTP(*, client)

Bases: Application

Serves as the fundemental HTTP server for Discord Interactions.

We recommend to not touch this class, unless you know what you’re doing

Parameters:

client (Client)

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:
  • ctx (Context) – The context of the command

  • e (Exception) – The exception that was raised

Return type:

MessageResponse | None

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

Parameters:

request (Request) – The incoming request object (not used by default)

Return type:

Response

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.

Parameters:
  • data (dict) – The data to respond with

  • status (int) – The status code to respond with

Return type:

Response

Returns:

The response object

multipart_response(body, *, status=200) Response

Respond with multipart data in a standardized way.

Parameters:
  • body (BaseResponse | None) – The body to respond with

  • status (int) – The status code to respond with

Return type:

Response

Returns:

The response object

start(*, host='127.0.0.1', port=8080) None

Start the HTTP server.

Parameters:
  • host (str) – Host to use, if not provided, it will use 127.0.0.1

  • port (int) – Port to use, if not provided, it will use 8080

Return type:

None