Context

discord_http.context module

class discord_http.context.Context(bot, data)

Bases: object

Represents the context of an interaction.

Parameters:
bot: Client

The bot/client instance that the interaction belongs to.

id: int

The ID of the interaction.

command_type: ApplicationCommandType

The type of the command, if any.

benchmark

A utility for benchmarking the time taken to execute code after responding to the interaction.

command: Command | None

The command that was executed, if any.

app_permissions: Permissions

The permissions of the application in the guild.

custom_id: str | None

The custom ID of the interaction, if any.

resolved: ResolvedValues

The resolved values of the interaction.

select_values: SelectValues

The selected values of the interaction, if any.

modal_values: dict[str, str | list[Member | Role | BaseChannel | Attachment | str]]

The values of the modal, if any.

options: list[dict]

The options of the interaction, if any.

entitlements: list[Entitlements]

The entitlements associated with the interaction.

last_message_id: int | None

The ID of the last message in the channel, if any.

recipients: list[User]

The recipients of the interaction, if any.

locale: Literal['id', 'da', 'de', 'en-GB', 'en-US', 'es-ES', 'fr', 'es-419', 'hr', 'it', 'lt', 'hu', 'nl', 'no', 'pl', 'pt-BR', 'ro', 'fi', 'sv-SE', 'vi', 'tr', 'cs', 'el', 'bg', 'ru', 'uk', 'hi', 'th', 'zh-CN', 'ja', 'zh-TW', 'ko'] | None

The locale of the interaction, if any.

guild_locale: Literal['id', 'da', 'de', 'en-GB', 'en-US', 'es-ES', 'fr', 'es-419', 'hr', 'it', 'lt', 'hu', 'nl', 'no', 'pl', 'pt-BR', 'ro', 'fi', 'sv-SE', 'vi', 'tr', 'cs', 'el', 'bg', 'ru', 'uk', 'hi', 'th', 'zh-CN', 'ja', 'zh-TW', 'ko'] | None

The locale of the guild, if any.

channel_id: int | None

The ID of the channel the interaction was sent in, if applicable.

message: Message | None

The message associated with the interaction, if any.

author: Member | User | None

The author of the message that was interacted with, if any.

user: Member | User

The user who initiated the interaction.

property type: InteractionType

Returns the type of the interaction.

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

property channel: BaseChannel | PartialChannel | None

Returns the channel the interaction was made in.

property channel_type: ChannelType

Returns the type of the channel.

property created_at: datetime

Returns the time the interaction was created.

property cooldown: Cooldown | None

Returns the context cooldown.

property expires_at: datetime

Returns the time the interaction expires.

is_expired() bool

Returns whether the interaction is expired.

Return type:

bool

property response: InteractionResponse

Returns the response to the interaction.

is_bot_dm() bool

Returns a boolean of whether the interaction was in the bot’s DM channel.

Return type:

bool

async defer(*, ephemeral=False, thinking=False) WebhookMessage

Defer the interaction after responding with an empty response in the initial interaction.

Parameters:
  • ephemeral (bool) – Whether the deferred message should be ephemeral

  • thinking (bool) – Whether the deferred message should show the “thinking” status

Return type:

WebhookMessage

Returns:

Returns the deferred message

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

async send_modal(modal) None

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

Parameters:

modal (Modal) – The modal to send

Raises:

TypeError – If modal is not a Modal instance

Return type:

None

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

async original_response() WebhookMessage

Fetch the original response to the interaction.

Return type:

WebhookMessage

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:
async delete_original_response() None

Delete the original response to the interaction.

Return type:

None

class discord_http.context.InteractionResponse(parent)

Bases: object

Represents the response to an interaction.

Parameters:

parent (Context)

pong() dict

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

Return type:

dict

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

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

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

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

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]