BaseInteraction

class discord.BaseInteraction

Bases: object

The Base-Class for a discord-interaction like klick a Button, select (an) option(s) of SelectMenu or using an application-command in discord For more general information’s about Interactions visit the Documentation of the Discord-API

The following attributes are always available:

id

The id of the interaction.

Type:

int

type

The type of the interaction.

Type:

InteractionType

user_id

The id of the user who triggered the interaction.

Type:

int

channel_id

The id of the channel where the interaction was triggered.

Type:

int

entitlements

For monetized apps entitlements of the user who triggered the interaction and optionally, if any.

This is available for all interaction types.

Type:

Optional[List[Entitlement]]

data

Some internal needed metadata for the interaction, depending on the type.

Type:

InteractionData

author_locale

The locale of the user who triggered the interaction.

Type:

Optional[Locale]

guild_locale

The locale of the guild where the interaction was triggered.

Type:

Optional[Locale]

guild_id

The id of the guild where the interaction was triggered, if any.

Type:

Optional[int]

app_permissions

The permissions of the bot in the channel where the interaction was triggered, if it was in a guild.

This is similar to interaction.channel.permissions_for(interaction.guild.me) but calculated on discord side.

Type:

Optional[Permissions]

author_permissions

The author’s permissions in the channel where the interaction was triggered, if it was in a guild.

This is similar to interaction.channel.permissions_for(interaction.author), but calculated on discord side.

Type:

Optional[Permissions]

property callback_message

The initial interaction response message, if any. (@original)

Type:

Optional[Union[Message, EphemeralMessage]

await edit(*, content=MISSING, embed=MISSING, embeds=MISSING, components=MISSING, attachments=MISSING, keep_existing_attachments=False, delete_after=None, allowed_mentions=MISSING, suppress_embeds=False)

This function is a coroutine.

Responds to the interaction by editing the original (message) or callback_message, depending on the type.

Parameters:
  • content (Optional[str]) – The new content to replace the message with. Could be None to remove the content.

  • embed (Optional[Embed]) – The new embed to replace the original with. Could be None to remove all embeds.

  • embeds (Optional[List[Embed]]) –

    A list containing up to 10 embeds to send. If None or empty, all embeds will be removed.

    If passed, embed does also count towards the limit of 10 embeds.

  • components (List[Union[ActionRow, List[Union[Button, Select]]]]) – A list of up to five ActionRow or list, each containing up to five Button or one Select like object.

  • attachments (List[Union[Attachment, File]]) –

    A list containing previous attachments to keep as well as new files to upload. You can use keep_existing_attachments to auto-add the existing attachments to the list. If None or empty, all attachments will be removed.

    Note

    New files will always appear under existing ones.

  • keep_existing_attachments (bool) –

    Whether to auto-add existing attachments to attachments, default False.

    Note

    Only needed when attachments are passed, otherwise will be ignored.

  • suppress_embeds (bool) – Whether to suppress embeds for the message. This removes all the embeds if set to True. If set to False this brings the embeds back if they were suppressed.

  • delete_after (Optional[float]) – If provided, the number of seconds to wait in the background before deleting the response we just edited. If the deletion fails, then it is silently ignored.

  • allowed_mentions (Optional[AllowedMentions]) – Controls the mentions being processed in this message. If this is passed, then the object is merged with allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

Raises:
  • TypeError – The interaction was already responded to with a modal, or it is an application-command that was not responded to.

  • NotFound: – The interaction is expired.

  • HTTPException – Editing the message failed.

Returns:

The edited message.

Return type:

Union[Message, EphemeralMessage]

await respond(content=None, *, tts=False, embed=None, embeds=None, components=None, file=None, files=None, delete_after=None, allowed_mentions=None, suppress_embeds=False, suppress_notifications=False, hidden=False)

This function is a coroutine.

Responds to an interaction by sending a message.

Parameters:
  • content (str) – The content of the message to send.

  • tts (bool) – Indicates if the message should be sent using text-to-speech.

  • embed (Embed) – The rich embed for the content.

  • embeds (List[Embed]) –

    A list containing up to 10 embeds.

    If passed, embed also counts towards the limit of 10.

  • components (List[Union[ActionRow, List[Union[Button, Select]]]]) – A list of up to five Button or one Select like object.

  • file (File) – The file to upload.

  • files (List[File]) – A list of files to upload. Must be a maximum of 10.

  • suppress_embeds (bool) – Whether to suppress embeds for the message.

  • suppress_notifications (bool) – Whether to suppress desktop- & push-notifications for the post starter-message.

  • delete_after (float) – If provided, the number of seconds to wait in the background before deleting the response we just sent. If the deletion fails, then it is silently ignored.

  • allowed_mentions (AllowedMentions) – Controls the mentions being processed in this message. If this is passed, then the object is merged with allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

  • hidden (Optional[bool]) – If True the message will be only visible for the performer of the interaction (e.g. author).

Raises:
  • TypeError – This interaction was already responded to with a modal.

  • NotFound – The interaction has expired.

  • HTTPException – Responding to the interaction failed.

await respond_with_modal(modal)

This function is a coroutine. Respond to an interaction with a popup modal.

Parameters:

modal (Modal) – The modal to send.

Raises:
await get_original_callback(raw=False)

This function is a coroutine. Fetch the original callback-message of the interaction.

Warning

This is an API-Call and should be used carefully

Parameters:

raw (Optional[bool]) – Whether to return the raw data from the api instead of a Message/EphemeralMessage.

Returns:

The original callback-message of the interaction.

Return type:

Union[Message,:class:EphemeralMessage], dict]

get_followup(id)

Gets a followup message of this interaction with the given id.

Parameters:

id (int) – The id of the followup message.

Returns:

The followup or None if there is none.

Return type:

Optional[Union[Message, EphemeralMessage]]

property created_at

Returns the Interaction’s creation time in UTC.

Returns:

datetime.datetime

property author

The Member that invoked the interaction. If channel is of type private or the user has left the guild, then it is a User instead.

Type:

Union[Member, User]

property channel
Union[

TextChannel, ThreadChannel, DMChannel, VoiceChannel, ForumPost, PartialMessageable

]: The channel where the interaction was invoked in.

property guild

The guild the interaction was invoked in, if there is one.

Type:

Optional[Guild]

property message_is_dm

An deprecated alias to is_dm.

Type:

bool

property is_dm

Whether the interaction was invoked in a DMChannel.

Type:

bool

property bot

Union[Client, Bot]: The Client/Bot instance of the bot.

ApplicationCommandInteraction

class discord.ApplicationCommandInteraction

Bases: BaseInteraction

Holds the data of an interaction when a ~discord.SlashCommand, UserCommand or MessageCommand is used and allows responding to it.

id

The id of the interaction.

Type:

int

type

The type of the interaction.

Type:

InteractionType

user_id

The id of the user who triggered the interaction.

Type:

int

channel_id

The id of the channel where the interaction was triggered.

Type:

int

messages

A mapping of message id’s to the message objects that were sent using respond.

Type:

Dict[int, Union[Message, EphemeralMessage]]

author_locale

The locale of the user who triggered the interaction.

Type:

Optional[Locale]

guild_locale

The locale of the guild where the interaction was triggered.

Type:

Optional[Locale]

guild_id

The id of the guild where the interaction was triggered, if any.

Type:

Optional[int]

app_permissions

The permissions of the bot in the channel where the interaction was triggered, if it was in a guild.

Type:

Optional[Permissions]

target

The resolved target of the interaction, if it is a user or message command.

Type:

Optional[Union[Member, Message]]

property command

Union[SlashCommand, UserCommand, MessageCommand]: The application-command that was invoked.

await defer(hidden=False)

Defers the interaction, the user sees a loading state

Parameters:

hidden (Optional[bool]) – Weather only the author of the command should see this

Raises:
Returns:

The Message containing the loading state

Return type:

Union[EphemeralMessage]

await respond_with_premium_required()

This function is a coroutine. Respond with an upgrade button, only available for apps with monetized apps enabled.

Note

You must respond with this one directly, without using any of defer() or respond().

property author

The Member that invoked the interaction. If channel is of type private or the user has left the guild, then it is a User instead.

Type:

Union[Member, User]

property bot

Union[Client, Bot]: The Client/Bot instance of the bot.

property callback_message

The initial interaction response message, if any. (@original)

Type:

Optional[Union[Message, EphemeralMessage]

property channel
Union[

TextChannel, ThreadChannel, DMChannel, VoiceChannel, ForumPost, PartialMessageable

]: The channel where the interaction was invoked in.

property created_at

Returns the Interaction’s creation time in UTC.

Returns:

datetime.datetime

await edit(*, content=MISSING, embed=MISSING, embeds=MISSING, components=MISSING, attachments=MISSING, keep_existing_attachments=False, delete_after=None, allowed_mentions=MISSING, suppress_embeds=False)

This function is a coroutine.

Responds to the interaction by editing the original (message) or callback_message, depending on the type.

Parameters:
  • content (Optional[str]) – The new content to replace the message with. Could be None to remove the content.

  • embed (Optional[Embed]) – The new embed to replace the original with. Could be None to remove all embeds.

  • embeds (Optional[List[Embed]]) –

    A list containing up to 10 embeds to send. If None or empty, all embeds will be removed.

    If passed, embed does also count towards the limit of 10 embeds.

  • components (List[Union[ActionRow, List[Union[Button, Select]]]]) – A list of up to five ActionRow or list, each containing up to five Button or one Select like object.

  • attachments (List[Union[Attachment, File]]) –

    A list containing previous attachments to keep as well as new files to upload. You can use keep_existing_attachments to auto-add the existing attachments to the list. If None or empty, all attachments will be removed.

    Note

    New files will always appear under existing ones.

  • keep_existing_attachments (bool) –

    Whether to auto-add existing attachments to attachments, default False.

    Note

    Only needed when attachments are passed, otherwise will be ignored.

  • suppress_embeds (bool) – Whether to suppress embeds for the message. This removes all the embeds if set to True. If set to False this brings the embeds back if they were suppressed.

  • delete_after (Optional[float]) – If provided, the number of seconds to wait in the background before deleting the response we just edited. If the deletion fails, then it is silently ignored.

  • allowed_mentions (Optional[AllowedMentions]) – Controls the mentions being processed in this message. If this is passed, then the object is merged with allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

Raises:
  • TypeError – The interaction was already responded to with a modal, or it is an application-command that was not responded to.

  • NotFound: – The interaction is expired.

  • HTTPException – Editing the message failed.

Returns:

The edited message.

Return type:

Union[Message, EphemeralMessage]

get_followup(id)

Gets a followup message of this interaction with the given id.

Parameters:

id (int) – The id of the followup message.

Returns:

The followup or None if there is none.

Return type:

Optional[Union[Message, EphemeralMessage]]

await get_original_callback(raw=False)

This function is a coroutine. Fetch the original callback-message of the interaction.

Warning

This is an API-Call and should be used carefully

Parameters:

raw (Optional[bool]) – Whether to return the raw data from the api instead of a Message/EphemeralMessage.

Returns:

The original callback-message of the interaction.

Return type:

Union[Message,:class:EphemeralMessage], dict]

property guild

The guild the interaction was invoked in, if there is one.

Type:

Optional[Guild]

property is_dm

Whether the interaction was invoked in a DMChannel.

Type:

bool

property message_is_dm

An deprecated alias to is_dm.

Type:

bool

await respond(content=None, *, tts=False, embed=None, embeds=None, components=None, file=None, files=None, delete_after=None, allowed_mentions=None, suppress_embeds=False, suppress_notifications=False, hidden=False)

This function is a coroutine.

Responds to an interaction by sending a message.

Parameters:
  • content (str) – The content of the message to send.

  • tts (bool) – Indicates if the message should be sent using text-to-speech.

  • embed (Embed) – The rich embed for the content.

  • embeds (List[Embed]) –

    A list containing up to 10 embeds.

    If passed, embed also counts towards the limit of 10.

  • components (List[Union[ActionRow, List[Union[Button, Select]]]]) – A list of up to five Button or one Select like object.

  • file (File) – The file to upload.

  • files (List[File]) – A list of files to upload. Must be a maximum of 10.

  • suppress_embeds (bool) – Whether to suppress embeds for the message.

  • suppress_notifications (bool) – Whether to suppress desktop- & push-notifications for the post starter-message.

  • delete_after (float) – If provided, the number of seconds to wait in the background before deleting the response we just sent. If the deletion fails, then it is silently ignored.

  • allowed_mentions (AllowedMentions) – Controls the mentions being processed in this message. If this is passed, then the object is merged with allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

  • hidden (Optional[bool]) – If True the message will be only visible for the performer of the interaction (e.g. author).

Raises:
  • TypeError – This interaction was already responded to with a modal.

  • NotFound – The interaction has expired.

  • HTTPException – Responding to the interaction failed.

await respond_with_modal(modal)

This function is a coroutine. Respond to an interaction with a popup modal.

Parameters:

modal (Modal) – The modal to send.

Raises:

ComponentInteraction

class discord.ComponentInteraction

Bases: BaseInteraction

Holds the data of an interaction with a button or select and allows responding to it.

id

The id of the interaction.

Type:

int

type

The type of the interaction.

Type:

InteractionType

user_id

The id of the user who triggered the interaction.

Type:

int

channel_id

The id of the channel where the interaction was triggered.

Type:

int

messages

A mapping of message id’s to the message objects that were sent using respond.

Type:

Dict[int, Union[Message, EphemeralMessage]]

author_locale

The locale of the user who triggered the interaction.

Type:

Optional[Locale]

guild_locale

The locale of the guild where the interaction was triggered.

Type:

Optional[Locale]

message

The message the component is attached to.

Type:

Optional[Union[Message, EphemeralMessage]

cached_message

The cached version of message, if any.

Type:

Optional[Union[Message, EphemeralMessage]

guild_id

The id of the guild where the interaction was triggered, if any.

Type:

Optional[int]

app_permissions

The permissions of the bot in the channel where the interaction was triggered, if it was in a guild.

Type:

Optional[Permissions]

match

The RegEx Match result of the custom_id of the component, if an on_click or on_select decorator was used.

Type:

Optional[Match]

property message_is_hidden

Whether the message has the ephemeral() flag.

Type:

bool

component

The component that was used

Type:

Union[Button, Select like objects]

await defer(type=('deferred_update_msg', 6), hidden=False)

Defers the interaction.

Parameters:
  • type (Union[Literal[5, 6]]) – Use 5 to edit the original message later and 6 to let the user sees a loading state and edit it later.

  • hidden (Optional[bool]) –

    Weather only the author of the command should see this, default True

    Note

    Only for deferred_msg_with_source (5).

Raises:
Returns:

The message containing the loading-state if deferred_msg_with_source (5) is used, else None.

Return type:

Optional[Union[EphemeralMessage]]

await respond_with_premium_required()

This function is a coroutine. Respond with an upgrade button, only available for apps with monetized apps enabled.

Note

You must respond with this one directly, without using any of defer() or respond().

property author

The Member that invoked the interaction. If channel is of type private or the user has left the guild, then it is a User instead.

Type:

Union[Member, User]

property bot

Union[Client, Bot]: The Client/Bot instance of the bot.

property callback_message

The initial interaction response message, if any. (@original)

Type:

Optional[Union[Message, EphemeralMessage]

property channel
Union[

TextChannel, ThreadChannel, DMChannel, VoiceChannel, ForumPost, PartialMessageable

]: The channel where the interaction was invoked in.

property created_at

Returns the Interaction’s creation time in UTC.

Returns:

datetime.datetime

await edit(*, content=MISSING, embed=MISSING, embeds=MISSING, components=MISSING, attachments=MISSING, keep_existing_attachments=False, delete_after=None, allowed_mentions=MISSING, suppress_embeds=False)

This function is a coroutine.

Responds to the interaction by editing the original (message) or callback_message, depending on the type.

Parameters:
  • content (Optional[str]) – The new content to replace the message with. Could be None to remove the content.

  • embed (Optional[Embed]) – The new embed to replace the original with. Could be None to remove all embeds.

  • embeds (Optional[List[Embed]]) –

    A list containing up to 10 embeds to send. If None or empty, all embeds will be removed.

    If passed, embed does also count towards the limit of 10 embeds.

  • components (List[Union[ActionRow, List[Union[Button, Select]]]]) – A list of up to five ActionRow or list, each containing up to five Button or one Select like object.

  • attachments (List[Union[Attachment, File]]) –

    A list containing previous attachments to keep as well as new files to upload. You can use keep_existing_attachments to auto-add the existing attachments to the list. If None or empty, all attachments will be removed.

    Note

    New files will always appear under existing ones.

  • keep_existing_attachments (bool) –

    Whether to auto-add existing attachments to attachments, default False.

    Note

    Only needed when attachments are passed, otherwise will be ignored.

  • suppress_embeds (bool) – Whether to suppress embeds for the message. This removes all the embeds if set to True. If set to False this brings the embeds back if they were suppressed.

  • delete_after (Optional[float]) – If provided, the number of seconds to wait in the background before deleting the response we just edited. If the deletion fails, then it is silently ignored.

  • allowed_mentions (Optional[AllowedMentions]) – Controls the mentions being processed in this message. If this is passed, then the object is merged with allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

Raises:
  • TypeError – The interaction was already responded to with a modal, or it is an application-command that was not responded to.

  • NotFound: – The interaction is expired.

  • HTTPException – Editing the message failed.

Returns:

The edited message.

Return type:

Union[Message, EphemeralMessage]

get_followup(id)

Gets a followup message of this interaction with the given id.

Parameters:

id (int) – The id of the followup message.

Returns:

The followup or None if there is none.

Return type:

Optional[Union[Message, EphemeralMessage]]

await get_original_callback(raw=False)

This function is a coroutine. Fetch the original callback-message of the interaction.

Warning

This is an API-Call and should be used carefully

Parameters:

raw (Optional[bool]) – Whether to return the raw data from the api instead of a Message/EphemeralMessage.

Returns:

The original callback-message of the interaction.

Return type:

Union[Message,:class:EphemeralMessage], dict]

property guild

The guild the interaction was invoked in, if there is one.

Type:

Optional[Guild]

property is_dm

Whether the interaction was invoked in a DMChannel.

Type:

bool

property message_is_dm

An deprecated alias to is_dm.

Type:

bool

await respond(content=None, *, tts=False, embed=None, embeds=None, components=None, file=None, files=None, delete_after=None, allowed_mentions=None, suppress_embeds=False, suppress_notifications=False, hidden=False)

This function is a coroutine.

Responds to an interaction by sending a message.

Parameters:
  • content (str) – The content of the message to send.

  • tts (bool) – Indicates if the message should be sent using text-to-speech.

  • embed (Embed) – The rich embed for the content.

  • embeds (List[Embed]) –

    A list containing up to 10 embeds.

    If passed, embed also counts towards the limit of 10.

  • components (List[Union[ActionRow, List[Union[Button, Select]]]]) – A list of up to five Button or one Select like object.

  • file (File) – The file to upload.

  • files (List[File]) – A list of files to upload. Must be a maximum of 10.

  • suppress_embeds (bool) – Whether to suppress embeds for the message.

  • suppress_notifications (bool) – Whether to suppress desktop- & push-notifications for the post starter-message.

  • delete_after (float) – If provided, the number of seconds to wait in the background before deleting the response we just sent. If the deletion fails, then it is silently ignored.

  • allowed_mentions (AllowedMentions) – Controls the mentions being processed in this message. If this is passed, then the object is merged with allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

  • hidden (Optional[bool]) – If True the message will be only visible for the performer of the interaction (e.g. author).

Raises:
  • TypeError – This interaction was already responded to with a modal.

  • NotFound – The interaction has expired.

  • HTTPException – Responding to the interaction failed.

await respond_with_modal(modal)

This function is a coroutine. Respond to an interaction with a popup modal.

Parameters:

modal (Modal) – The modal to send.

Raises:

AutocompleteInteraction

class discord.AutocompleteInteraction

Bases: BaseInteraction

Holds the data of an application command autocomplete interaction that will be received when autocomplete for a SlashCommandOption with autocomplete is set to True.

To respond with the autocomplete choices, use send_choices().

id

The id of the interaction.

Type:

int

type

The type of the interaction.

Type:

InteractionType

user_id

The id of the user who triggered the interaction.

Type:

int

channel_id

The id of the channel where the interaction was triggered.

Type:

int

author_locale

The locale of the user who triggered the interaction.

Type:

Optional[Locale]

guild_locale

The locale of the guild where the interaction was triggered.

Type:

Optional[Locale]

guild_id

The id of the guild where the interaction was triggered, if any.

Type:

Optional[int]

app_permissions

The permissions of the bot in the channel where the interaction was triggered, if it was in a guild.

Type:

Optional[Permissions]

property command

The slash-command for wich autocomplete was triggered.

Type:

Optional[SlashCommand]

property focused_option

Returns the currently focused option.

Type:

InteractionDataOption

property focused_option_name

Returns the name of the currently focused option.

Type:

str

await send_choices(choices)

Respond to the interaction with the choices the user should have.

Parameters:

choices (List[SlashCommandOptionChoice]) – A list of maximum 25 options the user could choose from.

Raises:
  • ValueError – When more than 25 choices are passed.

  • NotFound – You have been waited to long with responding to the interaction.

await suggest(choices)

An aliase for send_choices()

property author

The Member that invoked the interaction. If channel is of type private or the user has left the guild, then it is a User instead.

Type:

Union[Member, User]

property bot

Union[Client, Bot]: The Client/Bot instance of the bot.

property callback_message

The initial interaction response message, if any. (@original)

Type:

Optional[Union[Message, EphemeralMessage]

property channel
Union[

TextChannel, ThreadChannel, DMChannel, VoiceChannel, ForumPost, PartialMessageable

]: The channel where the interaction was invoked in.

property created_at

Returns the Interaction’s creation time in UTC.

Returns:

datetime.datetime

await get_original_callback(raw=False)

This function is a coroutine. Fetch the original callback-message of the interaction.

Warning

This is an API-Call and should be used carefully

Parameters:

raw (Optional[bool]) – Whether to return the raw data from the api instead of a Message/EphemeralMessage.

Returns:

The original callback-message of the interaction.

Return type:

Union[Message,:class:EphemeralMessage], dict]

property guild

The guild the interaction was invoked in, if there is one.

Type:

Optional[Guild]

property is_dm

Whether the interaction was invoked in a DMChannel.

Type:

bool

property message_is_dm

An deprecated alias to is_dm.

Type:

bool

ModalSubmitInteraction

class discord.ModalSubmitInteraction(state, data)

Bases: BaseInteraction

Holds the data of an interaction that will be received when the Submit button of a Modal is pressed and allows responding to it.

Note

You can’t respond to a modal submit interaction with another modal.

id

The id of the interaction.

Type:

int

type

The type of the interaction.

Type:

InteractionType

user_id

The id of the user who triggered the interaction.

Type:

int

channel_id

The id of the channel where the interaction was triggered.

Type:

int

messages

A mapping of message id’s to the message objects that were sent using respond.

Type:

Dict[int, Union[Message, EphemeralMessage]]

author_locale

The locale of the user who triggered the interaction.

Type:

Optional[Locale]

guild_locale

The locale of the guild where the interaction was triggered.

Type:

Optional[Locale]

cached_message

The cached version of message, if any.

Type:

Optional[Union[Message, EphemeralMessage]

guild_id

The id of the guild where the interaction was triggered, if any.

Type:

Optional[int]

app_permissions

The permissions of the bot in the channel where the interaction was triggered, if it was in a guild.

Type:

Optional[Permissions]

match

The RegEx Match result of the custom_id of the modal, if an on_submit decorator was used.

Type:

Optional[Match]

get_field(custom_id)

Gets the field wich custom_id match, if any.

Parameters:

custom_id (Union[str, Pattern]) –

The custom_id of the field to get.

Note

You can also pass a Pattern when you want to use dynamic custom_id’s. Only the first matching field will be returned.

Returns:

  • If custom_id is a str, the found TextInput is returned, if any.

  • if custom_id is a Pattern a tuple is returned containing the field

    wich custom_id matches and the corresponding Match, if any.

Return type:

Optional[Union[TextInput, Tuple[TextInput, Match]]]

property fields

Returns a list containing the fields of the Modal.

Type:

List[TextInput]

property custom_id

The Custom ID of the Modal

Returns:

The custom_id of the Modal.

Return type:

str

await respond_with_premium_required()

This function is a coroutine. Respond with an upgrade button, only available for apps with monetized apps enabled.

Note

You must respond with this one directly, without using any of defer() or respond().

property author

The Member that invoked the interaction. If channel is of type private or the user has left the guild, then it is a User instead.

Type:

Union[Member, User]

property bot

Union[Client, Bot]: The Client/Bot instance of the bot.

property callback_message

The initial interaction response message, if any. (@original)

Type:

Optional[Union[Message, EphemeralMessage]

property channel
Union[

TextChannel, ThreadChannel, DMChannel, VoiceChannel, ForumPost, PartialMessageable

]: The channel where the interaction was invoked in.

property created_at

Returns the Interaction’s creation time in UTC.

Returns:

datetime.datetime

await edit(*, content=MISSING, embed=MISSING, embeds=MISSING, components=MISSING, attachments=MISSING, keep_existing_attachments=False, delete_after=None, allowed_mentions=MISSING, suppress_embeds=False)

This function is a coroutine.

Responds to the interaction by editing the original (message) or callback_message, depending on the type.

Parameters:
  • content (Optional[str]) – The new content to replace the message with. Could be None to remove the content.

  • embed (Optional[Embed]) – The new embed to replace the original with. Could be None to remove all embeds.

  • embeds (Optional[List[Embed]]) –

    A list containing up to 10 embeds to send. If None or empty, all embeds will be removed.

    If passed, embed does also count towards the limit of 10 embeds.

  • components (List[Union[ActionRow, List[Union[Button, Select]]]]) – A list of up to five ActionRow or list, each containing up to five Button or one Select like object.

  • attachments (List[Union[Attachment, File]]) –

    A list containing previous attachments to keep as well as new files to upload. You can use keep_existing_attachments to auto-add the existing attachments to the list. If None or empty, all attachments will be removed.

    Note

    New files will always appear under existing ones.

  • keep_existing_attachments (bool) –

    Whether to auto-add existing attachments to attachments, default False.

    Note

    Only needed when attachments are passed, otherwise will be ignored.

  • suppress_embeds (bool) – Whether to suppress embeds for the message. This removes all the embeds if set to True. If set to False this brings the embeds back if they were suppressed.

  • delete_after (Optional[float]) – If provided, the number of seconds to wait in the background before deleting the response we just edited. If the deletion fails, then it is silently ignored.

  • allowed_mentions (Optional[AllowedMentions]) – Controls the mentions being processed in this message. If this is passed, then the object is merged with allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

Raises:
  • TypeError – The interaction was already responded to with a modal, or it is an application-command that was not responded to.

  • NotFound: – The interaction is expired.

  • HTTPException – Editing the message failed.

Returns:

The edited message.

Return type:

Union[Message, EphemeralMessage]

get_followup(id)

Gets a followup message of this interaction with the given id.

Parameters:

id (int) – The id of the followup message.

Returns:

The followup or None if there is none.

Return type:

Optional[Union[Message, EphemeralMessage]]

await get_original_callback(raw=False)

This function is a coroutine. Fetch the original callback-message of the interaction.

Warning

This is an API-Call and should be used carefully

Parameters:

raw (Optional[bool]) – Whether to return the raw data from the api instead of a Message/EphemeralMessage.

Returns:

The original callback-message of the interaction.

Return type:

Union[Message,:class:EphemeralMessage], dict]

property guild

The guild the interaction was invoked in, if there is one.

Type:

Optional[Guild]

property is_dm

Whether the interaction was invoked in a DMChannel.

Type:

bool

property message_is_dm

An deprecated alias to is_dm.

Type:

bool

await respond(content=None, *, tts=False, embed=None, embeds=None, components=None, file=None, files=None, delete_after=None, allowed_mentions=None, suppress_embeds=False, suppress_notifications=False, hidden=False)

This function is a coroutine.

Responds to an interaction by sending a message.

Parameters:
  • content (str) – The content of the message to send.

  • tts (bool) – Indicates if the message should be sent using text-to-speech.

  • embed (Embed) – The rich embed for the content.

  • embeds (List[Embed]) –

    A list containing up to 10 embeds.

    If passed, embed also counts towards the limit of 10.

  • components (List[Union[ActionRow, List[Union[Button, Select]]]]) – A list of up to five Button or one Select like object.

  • file (File) – The file to upload.

  • files (List[File]) – A list of files to upload. Must be a maximum of 10.

  • suppress_embeds (bool) – Whether to suppress embeds for the message.

  • suppress_notifications (bool) – Whether to suppress desktop- & push-notifications for the post starter-message.

  • delete_after (float) – If provided, the number of seconds to wait in the background before deleting the response we just sent. If the deletion fails, then it is silently ignored.

  • allowed_mentions (AllowedMentions) – Controls the mentions being processed in this message. If this is passed, then the object is merged with allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in allowed_mentions. If no object is passed at all then the defaults given by allowed_mentions are used instead.

  • hidden (Optional[bool]) – If True the message will be only visible for the performer of the interaction (e.g. author).

Raises:
  • TypeError – This interaction was already responded to with a modal.

  • NotFound – The interaction has expired.

  • HTTPException – Responding to the interaction failed.

Localizations

Methods
class discord.Localizations

Bases: object

Represents a dict with localized values. These are used for application-commands, options and choices name_localizations and description_localizations

See Locale for a list of available locals.

Example

Localizations(
    en_US='Hello World!',
    de='Hallo Welt!',
    fr='Bonjour le monde!'
    uk='Привіт світ!'
)

Using the full language name is also possible.

Localizations(
    english_us='Hello World!',
    german='Hallo Welt!',
    french='Bonjour le monde!'
    ukrainian='Привіт світ!'
)
Parameters:

kwargs (Any) –

Keyword only arguments in format language='Value' As language you could use any of discord.Locale s members. See table above.

Note

Values follow the same restrictions as the target they are used for. e.g. description, name, etc.

update(_Localizations__m)

Similar to dict.update()

from_target(target, *, default=None)

Returns the value for the local of the object (if it’s set), or default`(:class:`None)

Parameters:
  • target (Union[Guild, BaseInteraction]) – The target witch locale to use. If it is of type BaseInteraction (or any subclass) it returns takes the local of the author.

  • default (Optional[Any]) – The value or an object to return by default if there is no value for the locale of target set. Default to None or english_US/english_GB

Returns:

The value of the locale or None if there is no value for the locale set.

Return type:

Union[str, None]

Raises:

TypeError – If target is of the wrong type.

InteractionDataOption

class discord.interactions.InteractionDataOption

Bases: object

Represents a slash-command option passed via a command. By default, you only get in contact with this using focused_option.

name

The name of the option

Type:

str

type

The type of the option

Type:

OptionType

property value

Returns the value of the option (what the user passed)

Type:

Union[str, int, float]

property focused

Whether this option is currently focused (for autocomplete)

Type:

bool

property options

For sub-command (groups) the sub-command or the actual options

Type:

Optional[List[InteractionDataOption]]