Context

discord_http.context module

class discord_http.context.Context(bot, data)

Bases: object

Parameters:
property channel: BaseChannel | PartialChannel | None

Returns the channel the interaction was made in.

property channel_type: ChannelType

Returns the type of the channel.

property cooldown: Cooldown | None

Returns the context cooldown.

async create_followup_response(content=<MISSING>, *, embed=<MISSING>, embeds=<MISSING>, file=<MISSING>, files=<MISSING>, ephemeral=False, view=<MISSING>, tts=False, type=4, allowed_mentions=<MISSING>, poll=<MISSING>, flags=<MISSING>, delete_after=None) WebhookMessage

Creates a new followup response to the interaction.

Do not use this to create a followup response when defer was called before. Use edit_original_response instead.

Parameters:
  • content (str | None) – Content of the message

  • embed (Embed | None) – Embed of the message

  • embeds (list[Embed] | None) – Embeds of the message

  • file (File | None) – File of the message

  • files (list[File] | None) – Files of the message

  • ephemeral (bool | None) – Whether the message should be sent as ephemeral

  • view (View | None) – Components of the message

  • type (ResponseType | int) – Which type of response should be sent

  • allowed_mentions (AllowedMentions | None) – Allowed mentions of the message

  • wait – Whether to wait for the message to be sent

  • thread_id – Thread ID to send the message to

  • poll (Poll | None) – Poll to send with the message

  • tts (bool | None) – Whether the message should be sent as TTS

  • flags (MessageFlags | None) – Flags of the message

  • delete_after (float | None) – How long to wait before deleting the message

Return type:

WebhookMessage

Returns:

Returns the message that was sent

property created_at: datetime

Returns the time the interaction was created.

async delete_original_response() None

Delete the original response to the interaction.

Return type:

None

async edit_original_response(*, content=<MISSING>, embed=<MISSING>, embeds=<MISSING>, view=<MISSING>, attachment=<MISSING>, attachments=<MISSING>, allowed_mentions=<MISSING>, flags=<MISSING>) WebhookMessage

Edit the original response to the interaction.

Return type:

WebhookMessage

Parameters:
property expires_at: datetime

Returns the time the interaction expires.

property guild: Guild | PartialGuild | None

Returns the guild the interaction was made in.

If you are using gateway cache, it can return full object too

is_expired() bool

Returns whether the interaction is expired.

Return type:

bool

async original_response() WebhookMessage

Fetch the original response to the interaction.

Return type:

WebhookMessage

property response: InteractionResponse

Returns the response to the interaction.

async send(content=<MISSING>, *, embed=<MISSING>, embeds=<MISSING>, file=<MISSING>, files=<MISSING>, ephemeral=False, view=<MISSING>, tts=False, type=4, allowed_mentions=<MISSING>, poll=<MISSING>, flags=<MISSING>, delete_after=None) WebhookMessage

Send a message after responding with an empty response in the initial interaction.

Parameters:
  • content (str | None) – Content of the message

  • embed (Embed | None) – Embed of the message

  • embeds (list[Embed] | None) – Embeds of the message

  • file (File | None) – File of the message

  • files (list[File] | None) – Files of the message

  • ephemeral (bool | None) – Whether the message should be sent as ephemeral

  • view (View | None) – Components of the message

  • type (ResponseType | int) – Which type of response should be sent

  • allowed_mentions (AllowedMentions | None) – Allowed mentions of the message

  • wait – Whether to wait for the message to be sent

  • thread_id – Thread ID to send the message to

  • poll (Poll | None) – Poll to send with the message

  • tts (bool | None) – Whether the message should be sent as TTS

  • flags (MessageFlags | None) – Flags of the message

  • delete_after (float | None) – How long to wait before deleting the message

Return type:

WebhookMessage

Returns:

Returns the message that was sent

class discord_http.context.InteractionResponse(parent)

Bases: object

Parameters:

parent (Context)

defer(ephemeral=False, thinking=False, flags=<MISSING>, call_after=None) DeferResponse

Defer the response to the interaction.

Parameters:
  • ephemeral (bool) – If the response should be ephemeral (show only to the user)

  • thinking (bool) – If the response should show the “thinking” status

  • flags (MessageFlags | None) – The flags of the message (overrides ephemeral)

  • call_after (Callable | None) – A coroutine to run after the response is sent

Return type:

DeferResponse

Returns:

The response to the interaction

Raises:

TypeError – If call_after is not a coroutine

edit_message(*, content=<MISSING>, embed=<MISSING>, embeds=<MISSING>, view=<MISSING>, attachment=<MISSING>, attachments=<MISSING>, allowed_mentions=<MISSING>, flags=<MISSING>, call_after=None) MessageResponse

Edit the original message of the interaction.

Parameters:
  • content (str | None) – Content of the message

  • embed (Embed | None) – Embed to edit the message with

  • embeds (list[Embed] | None) – Multiple embeds to edit the message with

  • view (View | None) – Components to include in the message

  • attachment (File | None) – New file to edit the message with

  • attachments (list[File] | None) – Multiple new files to edit the message with

  • allowed_mentions (AllowedMentions | None) – Allowed mentions for the message

  • flags (MessageFlags | None) – The flags of the message

  • call_after (Callable | None) – A coroutine to run after the response is sent

Return type:

MessageResponse

Returns:

The response to the interaction

Raises:
  • ValueError

    • If both embed and embeds are passed - If both attachment and attachments are passed

  • TypeError – If call_after is not a coroutine

pong() dict

Only used to acknowledge a ping from Discord Developer portal Interaction URL.

Return type:

dict

send_autocomplete(choices) AutocompleteResponse

Send an autocomplete response to the interaction.

Parameters:

choices (dict[Any, str]) – The choices to send

Return type:

AutocompleteResponse

Returns:

The response to the interaction

Raises:

TypeError

  • If choices is not a dict - If choices is not a dict[str | int | float, str]

send_empty(*, call_after=None) EmptyResponse

Send an empty response to the interaction.

Parameters:

call_after (Callable | None) – A coroutine to run after the response is sent

Return type:

EmptyResponse

Returns:

The response to the interaction

send_message(content=<MISSING>, *, embed=<MISSING>, embeds=<MISSING>, file=<MISSING>, files=<MISSING>, ephemeral=False, view=<MISSING>, tts=False, type=4, allowed_mentions=<MISSING>, poll=<MISSING>, flags=<MISSING>, call_after=None) MessageResponse

Send a message to the interaction.

Parameters:
  • content (str | None) – Content of the message

  • embed (Embed | None) – The embed to send

  • embeds (list[Embed] | None) – Multiple embeds to send

  • file (File | None) – A file to send

  • files (list[File] | None) – Multiple files to send

  • ephemeral (bool | None) – If the message should be ephemeral (show only to the user)

  • view (View | None) – Components to include in the message

  • tts (bool | None) – Whether the message should be sent using text-to-speech

  • type (ResponseType | int) – The type of response to send

  • allowed_mentions (AllowedMentions | None) – Allowed mentions for the message

  • flags (MessageFlags | None) – The flags of the message (overrides ephemeral)

  • poll (Poll | None) – The poll to be sent

  • call_after (Callable | None) – A coroutine to run after the response is sent

Return type:

MessageResponse

Returns:

The response to the interaction

Raises:
  • ValueError

    • If both embed and embeds are passed - If both file and files are passed

  • TypeError – If call_after is not a coroutine

send_modal(modal, *, call_after=None) ModalResponse

Send a modal to the interaction.

Parameters:
  • modal (Modal) – The modal to send

  • call_after (Callable | None) – A coroutine to run after the response is sent

Return type:

ModalResponse

Returns:

The response to the interaction

Raises:

TypeError

  • If modal is not a Modal instance - If call_after is not a coroutine