Interactions¶
This sections documents everything related to interactions - special type of webhooks used for communication between user and client. Currently the only things Discord sends interactions for are message components and application commands.
Discord Models¶
Interaction¶
- asyncdelete_original_message
- asyncdelete_original_response
- asyncedit_original_message
- asyncedit_original_response
- defis_expired
- asyncoriginal_message
- asyncoriginal_response
- asyncsend
- class disnake.Interaction[source]¶
A base class representing a user-initiated Discord interaction.
An interaction happens when a user performs an action that the client needs to be notified of. Current examples are application commands and components.
New in version 2.0.
- data¶
The interaction’s raw data. This might be replaced with a more processed version in subclasses.
- Type:
Mapping[
str, Any]
- type¶
The interaction’s type.
- Type:
- guild_locale¶
The selected language of the interaction’s guild. This value is only meaningful in guilds with
COMMUNITYfeature and receives a default value otherwise. If the interaction was in a DM, then this value isNone.New in version 2.4.
- Type:
Optional[
Locale]
- original_message()[source]¶
An alias of
original_response().
- edit_original_message()[source]¶
An alias of
edit_original_response().
- delete_original_message()[source]¶
An alias of
delete_original_response().
- property bot[source]¶
The bot handling the interaction.
Only applicable when used with
Bot. This is an alias forclient.- Type:
- property user[source]¶
The user or member that sent the interaction. There is an alias for this named
author.
- me¶
Union[
Member,ClientUser]: Similar toGuild.meexcept it may return theClientUserin private message contexts.
- channel¶
The channel the interaction was sent from.
Note that due to a Discord limitation, threads that the bot cannot access and DM channels are not resolved since there is no data to complete them. These are
PartialMessageableinstead.If you want to compute the interaction author’s or bot’s permissions in the channel, consider using
permissionsorapp_permissionsinstead.- Type:
Union[
abc.GuildChannel,Thread,PartialMessageable]
- property permissions[source]¶
The resolved permissions of the member in the channel, including overwrites.
In a guild context, this is provided directly by Discord.
In a non-guild context this will be an instance of
Permissions.private_channel().- Type:
- property app_permissions[source]¶
The resolved permissions of the bot in the channel, including overwrites.
In a guild context, this is provided directly by Discord.
In a non-guild context this will be an instance of
Permissions.private_channel().New in version 2.6.
- Type:
- response¶
Returns an object responsible for handling responding to the interaction.
A response can only be done once. If secondary messages need to be sent, consider using
followupinstead.- Type:
- expires_at¶
Returns the interaction’s expiration time in UTC.
This is exactly 15 minutes after the interaction was created.
New in version 2.5.
- Type:
- is_expired()[source]¶
Whether the interaction can still be used to make requests to Discord.
This does not take into account the 3 second limit for the initial response.
New in version 2.5.
- Return type:
- await original_response()[source]¶
This function is a coroutine.
Fetches the original interaction response message associated with the interaction.
Here is a table with response types and their associated original response:
Response type
Original response
The message you sent
The message you edited
The message with thinking state (bot is thinking…)
Other response types
None
Repeated calls to this will return a cached value.
Changed in version 2.6: This function was renamed from
original_message.- Raises:
HTTPException – Fetching the original response message failed.
- Returns:
The original interaction response message.
- Return type:
- await edit_original_response(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., view=..., components=..., allowed_mentions=None)[source]¶
This function is a coroutine.
Edits the original, previously sent interaction response message.
This is a lower level interface to
InteractionMessage.edit()in case you do not want to fetch the message and save an HTTP request.This method is also the only way to edit the original response if the message sent was ephemeral.
Note
If the original response message has embeds with images that were created from local files (using the
fileparameter withEmbed.set_image()orEmbed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by settingfile/files/attachments, or adding an embed with local files).Changed in version 2.6: This function was renamed from
edit_original_message.- Parameters:
content (Optional[
str]) – The content to edit the message with, orNoneto clear it.embed (Optional[
Embed]) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.embeds (List[
Embed]) – The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with theembedparameter. To remove all embeds[]should be passed.file (
File) – The file to upload. This cannot be mixed with thefilesparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.files (List[
File]) – A list of files to upload. This cannot be mixed with thefileparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.attachments (Optional[List[
Attachment]]) –A list of attachments to keep in the message. If
[]orNoneis passed then all existing attachments are removed. Keeps existing attachments if not provided.New in version 2.2.
Changed in version 2.5: Supports passing
Noneto clear attachments.view (Optional[
View]) – The updated view to update this message with. This cannot be mixed withcomponents. IfNoneis passed then the view is removed.components (Optional[Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]]) –A list of components to update this message with. This cannot be mixed with
view. IfNoneis passed then the components are removed.New in version 2.4.
allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embedandembedsorfileandfilesValueError – The length of
embedswas invalid.
- Returns:
The newly edited message.
- Return type:
- await delete_original_response(*, delay=None)[source]¶
This function is a coroutine.
Deletes the original interaction response message.
This is a lower level interface to
InteractionMessage.delete()in case you do not want to fetch the message and save an HTTP request.Changed in version 2.6: This function was renamed from
delete_original_message.- Parameters:
delay (
float) – If provided, the number of seconds to wait in the background before deleting the original response message. If the deletion fails, then it is silently ignored.- Raises:
HTTPException – Deleting the message failed.
Forbidden – Deleted a message that is not yours.
- await send(content=None, *, embed=..., embeds=..., file=..., files=..., allowed_mentions=..., view=..., components=..., tts=False, ephemeral=False, suppress_embeds=False, delete_after=...)[source]¶
This function is a coroutine.
Sends a message using either
response.send_messageorfollowup.send.If the interaction hasn’t been responded to yet, this method will call
response.send_message. Otherwise, it will callfollowup.send.Note
This method does not return a
Messageobject. If you need a message object, useoriginal_response()to fetch it, or usefollowup.senddirectly instead of this method if you’re sending a followup message.- Parameters:
content (Optional[
str]) – The content of the message to send.embed (
Embed) – The rich embed for the content to send. This cannot be mixed with theembedsparameter.embeds (List[
Embed]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembedparameter.file (
File) – The file to upload. This cannot be mixed with thefilesparameter.files (List[
File]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefileparameter.allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. If this is passed, then the object is merged withClient.allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inClient.allowed_mentions. If no object is passed at all then the defaults given byClient.allowed_mentionsare used instead.tts (
bool) – Whether the message should be sent using text-to-speech.view (
disnake.ui.View) – The view to send with the message. This cannot be mixed withcomponents.components (Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]) –A list of components to send with the message. This cannot be mixed with
view.New in version 2.4.
ephemeral (
bool) – Whether the message should only be visible to the user who started the interaction. If a view is sent with an ephemeral message and it has no timeout set then the timeout is set to 15 minutes.suppress_embeds (
bool) –Whether to suppress embeds for the message. This hides all embeds from the UI if set to
True.New in version 2.5.
delete_after (
float) – If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.
- Raises:
HTTPException – Sending the message failed.
TypeError – You specified both
embedandembeds.ValueError – The length of
embedswas invalid.
ApplicationCommandInteraction¶
- asyncdelete_original_message
- asyncdelete_original_response
- asyncedit_original_message
- asyncedit_original_response
- defis_expired
- asyncoriginal_message
- asyncoriginal_response
- asyncsend
- class disnake.ApplicationCommandInteraction[source]¶
Represents an interaction with an application command.
Current examples are slash commands, user commands and message commands.
New in version 2.1.
- type¶
The interaction’s type.
- Type:
- guild_locale¶
The selected language of the interaction’s guild. This value is only meaningful in guilds with
COMMUNITYfeature and receives a default value otherwise. If the interaction was in a DM, then this value isNone.New in version 2.4.
- Type:
Optional[
Locale]
- data¶
The wrapped interaction data.
- application_command¶
The command invoked by the interaction.
- original_message()[source]¶
An alias of
original_response().
- edit_original_message()[source]¶
An alias of
edit_original_response().
- delete_original_message()[source]¶
An alias of
delete_original_response().
- property filled_options[source]¶
The options of the command (or sub-command) being invoked
- Type:
Dict[
str,Any]
- property app_permissions[source]¶
The resolved permissions of the bot in the channel, including overwrites.
In a guild context, this is provided directly by Discord.
In a non-guild context this will be an instance of
Permissions.private_channel().New in version 2.6.
- Type:
- property bot[source]¶
The bot handling the interaction.
Only applicable when used with
Bot. This is an alias forclient.- Type:
- channel¶
The channel the interaction was sent from.
Note that due to a Discord limitation, threads that the bot cannot access and DM channels are not resolved since there is no data to complete them. These are
PartialMessageableinstead.If you want to compute the interaction author’s or bot’s permissions in the channel, consider using
permissionsorapp_permissionsinstead.- Type:
Union[
abc.GuildChannel,Thread,PartialMessageable]
- await delete_original_response(*, delay=None)[source]¶
This function is a coroutine.
Deletes the original interaction response message.
This is a lower level interface to
InteractionMessage.delete()in case you do not want to fetch the message and save an HTTP request.Changed in version 2.6: This function was renamed from
delete_original_message.- Parameters:
delay (
float) – If provided, the number of seconds to wait in the background before deleting the original response message. If the deletion fails, then it is silently ignored.- Raises:
HTTPException – Deleting the message failed.
Forbidden – Deleted a message that is not yours.
- await edit_original_response(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., view=..., components=..., allowed_mentions=None)[source]¶
This function is a coroutine.
Edits the original, previously sent interaction response message.
This is a lower level interface to
InteractionMessage.edit()in case you do not want to fetch the message and save an HTTP request.This method is also the only way to edit the original response if the message sent was ephemeral.
Note
If the original response message has embeds with images that were created from local files (using the
fileparameter withEmbed.set_image()orEmbed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by settingfile/files/attachments, or adding an embed with local files).Changed in version 2.6: This function was renamed from
edit_original_message.- Parameters:
content (Optional[
str]) – The content to edit the message with, orNoneto clear it.embed (Optional[
Embed]) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.embeds (List[
Embed]) – The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with theembedparameter. To remove all embeds[]should be passed.file (
File) – The file to upload. This cannot be mixed with thefilesparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.files (List[
File]) – A list of files to upload. This cannot be mixed with thefileparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.attachments (Optional[List[
Attachment]]) –A list of attachments to keep in the message. If
[]orNoneis passed then all existing attachments are removed. Keeps existing attachments if not provided.New in version 2.2.
Changed in version 2.5: Supports passing
Noneto clear attachments.view (Optional[
View]) – The updated view to update this message with. This cannot be mixed withcomponents. IfNoneis passed then the view is removed.components (Optional[Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]]) –A list of components to update this message with. This cannot be mixed with
view. IfNoneis passed then the components are removed.New in version 2.4.
allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embedandembedsorfileandfilesValueError – The length of
embedswas invalid.
- Returns:
The newly edited message.
- Return type:
- expires_at¶
Returns the interaction’s expiration time in UTC.
This is exactly 15 minutes after the interaction was created.
New in version 2.5.
- Type:
- is_expired()[source]¶
Whether the interaction can still be used to make requests to Discord.
This does not take into account the 3 second limit for the initial response.
New in version 2.5.
- Return type:
- me¶
Union[
Member,ClientUser]: Similar toGuild.meexcept it may return theClientUserin private message contexts.
- await original_response()[source]¶
This function is a coroutine.
Fetches the original interaction response message associated with the interaction.
Here is a table with response types and their associated original response:
Response type
Original response
The message you sent
The message you edited
The message with thinking state (bot is thinking…)
Other response types
None
Repeated calls to this will return a cached value.
Changed in version 2.6: This function was renamed from
original_message.- Raises:
HTTPException – Fetching the original response message failed.
- Returns:
The original interaction response message.
- Return type:
- property permissions[source]¶
The resolved permissions of the member in the channel, including overwrites.
In a guild context, this is provided directly by Discord.
In a non-guild context this will be an instance of
Permissions.private_channel().- Type:
- response¶
Returns an object responsible for handling responding to the interaction.
A response can only be done once. If secondary messages need to be sent, consider using
followupinstead.- Type:
- await send(content=None, *, embed=..., embeds=..., file=..., files=..., allowed_mentions=..., view=..., components=..., tts=False, ephemeral=False, suppress_embeds=False, delete_after=...)[source]¶
This function is a coroutine.
Sends a message using either
response.send_messageorfollowup.send.If the interaction hasn’t been responded to yet, this method will call
response.send_message. Otherwise, it will callfollowup.send.Note
This method does not return a
Messageobject. If you need a message object, useoriginal_response()to fetch it, or usefollowup.senddirectly instead of this method if you’re sending a followup message.- Parameters:
content (Optional[
str]) – The content of the message to send.embed (
Embed) – The rich embed for the content to send. This cannot be mixed with theembedsparameter.embeds (List[
Embed]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembedparameter.file (
File) – The file to upload. This cannot be mixed with thefilesparameter.files (List[
File]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefileparameter.allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. If this is passed, then the object is merged withClient.allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inClient.allowed_mentions. If no object is passed at all then the defaults given byClient.allowed_mentionsare used instead.tts (
bool) – Whether the message should be sent using text-to-speech.view (
disnake.ui.View) – The view to send with the message. This cannot be mixed withcomponents.components (Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]) –A list of components to send with the message. This cannot be mixed with
view.New in version 2.4.
ephemeral (
bool) – Whether the message should only be visible to the user who started the interaction. If a view is sent with an ephemeral message and it has no timeout set then the timeout is set to 15 minutes.suppress_embeds (
bool) –Whether to suppress embeds for the message. This hides all embeds from the UI if set to
True.New in version 2.5.
delete_after (
float) – If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.
- Raises:
HTTPException – Sending the message failed.
TypeError – You specified both
embedandembeds.ValueError – The length of
embedswas invalid.
GuildCommandInteraction¶
- class disnake.GuildCommandInteraction[source]¶
An
ApplicationCommandInteractionsubclass, primarily meant for annotations.This prevents the command from being invoked in DMs by automatically setting
ApplicationCommand.dm_permissiontoFalsefor user/message commands and top-level slash commands.Note that this does not apply to slash subcommands, subcommand groups, or autocomplete callbacks.
Additionally, annotations of some attributes are modified to match the expected types in guilds.
UserCommandInteraction¶
- class disnake.UserCommandInteraction[source]¶
An
ApplicationCommandInteractionsubclass meant for annotations.No runtime behavior is changed but annotations are modified to seem like the interaction is specifically a user command.
MessageCommandInteraction¶
- class disnake.MessageCommandInteraction[source]¶
An
ApplicationCommandInteractionsubclass meant for annotations.No runtime behavior is changed but annotations are modified to seem like the interaction is specifically a message command.
MessageInteraction¶
- asyncdelete_original_message
- asyncdelete_original_response
- asyncedit_original_message
- asyncedit_original_response
- defis_expired
- asyncoriginal_message
- asyncoriginal_response
- asyncsend
- class disnake.MessageInteraction[source]¶
Represents an interaction with a message component.
Current examples are buttons and dropdowns.
New in version 2.1.
- type¶
The interaction type.
- Type:
- guild_locale¶
The selected language of the interaction’s guild. This value is only meaningful in guilds with
COMMUNITYfeature and receives a default value otherwise. If the interaction was in a DM, then this value isNone.New in version 2.4.
- Type:
Optional[
Locale]
- data¶
The wrapped interaction data.
- Type:
- original_message()[source]¶
An alias of
original_response().
- edit_original_message()[source]¶
An alias of
edit_original_response().
- delete_original_message()[source]¶
An alias of
delete_original_response().
- component¶
The component the user interacted with
- Type:
Union[
Button,BaseSelectMenu]
- property app_permissions[source]¶
The resolved permissions of the bot in the channel, including overwrites.
In a guild context, this is provided directly by Discord.
In a non-guild context this will be an instance of
Permissions.private_channel().New in version 2.6.
- Type:
- property bot[source]¶
The bot handling the interaction.
Only applicable when used with
Bot. This is an alias forclient.- Type:
- channel¶
The channel the interaction was sent from.
Note that due to a Discord limitation, threads that the bot cannot access and DM channels are not resolved since there is no data to complete them. These are
PartialMessageableinstead.If you want to compute the interaction author’s or bot’s permissions in the channel, consider using
permissionsorapp_permissionsinstead.- Type:
Union[
abc.GuildChannel,Thread,PartialMessageable]
- await delete_original_response(*, delay=None)[source]¶
This function is a coroutine.
Deletes the original interaction response message.
This is a lower level interface to
InteractionMessage.delete()in case you do not want to fetch the message and save an HTTP request.Changed in version 2.6: This function was renamed from
delete_original_message.- Parameters:
delay (
float) – If provided, the number of seconds to wait in the background before deleting the original response message. If the deletion fails, then it is silently ignored.- Raises:
HTTPException – Deleting the message failed.
Forbidden – Deleted a message that is not yours.
- await edit_original_response(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., view=..., components=..., allowed_mentions=None)[source]¶
This function is a coroutine.
Edits the original, previously sent interaction response message.
This is a lower level interface to
InteractionMessage.edit()in case you do not want to fetch the message and save an HTTP request.This method is also the only way to edit the original response if the message sent was ephemeral.
Note
If the original response message has embeds with images that were created from local files (using the
fileparameter withEmbed.set_image()orEmbed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by settingfile/files/attachments, or adding an embed with local files).Changed in version 2.6: This function was renamed from
edit_original_message.- Parameters:
content (Optional[
str]) – The content to edit the message with, orNoneto clear it.embed (Optional[
Embed]) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.embeds (List[
Embed]) – The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with theembedparameter. To remove all embeds[]should be passed.file (
File) – The file to upload. This cannot be mixed with thefilesparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.files (List[
File]) – A list of files to upload. This cannot be mixed with thefileparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.attachments (Optional[List[
Attachment]]) –A list of attachments to keep in the message. If
[]orNoneis passed then all existing attachments are removed. Keeps existing attachments if not provided.New in version 2.2.
Changed in version 2.5: Supports passing
Noneto clear attachments.view (Optional[
View]) – The updated view to update this message with. This cannot be mixed withcomponents. IfNoneis passed then the view is removed.components (Optional[Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]]) –A list of components to update this message with. This cannot be mixed with
view. IfNoneis passed then the components are removed.New in version 2.4.
allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embedandembedsorfileandfilesValueError – The length of
embedswas invalid.
- Returns:
The newly edited message.
- Return type:
- expires_at¶
Returns the interaction’s expiration time in UTC.
This is exactly 15 minutes after the interaction was created.
New in version 2.5.
- Type:
- is_expired()[source]¶
Whether the interaction can still be used to make requests to Discord.
This does not take into account the 3 second limit for the initial response.
New in version 2.5.
- Return type:
- me¶
Union[
Member,ClientUser]: Similar toGuild.meexcept it may return theClientUserin private message contexts.
- await original_response()[source]¶
This function is a coroutine.
Fetches the original interaction response message associated with the interaction.
Here is a table with response types and their associated original response:
Response type
Original response
The message you sent
The message you edited
The message with thinking state (bot is thinking…)
Other response types
None
Repeated calls to this will return a cached value.
Changed in version 2.6: This function was renamed from
original_message.- Raises:
HTTPException – Fetching the original response message failed.
- Returns:
The original interaction response message.
- Return type:
- property permissions[source]¶
The resolved permissions of the member in the channel, including overwrites.
In a guild context, this is provided directly by Discord.
In a non-guild context this will be an instance of
Permissions.private_channel().- Type:
- response¶
Returns an object responsible for handling responding to the interaction.
A response can only be done once. If secondary messages need to be sent, consider using
followupinstead.- Type:
- await send(content=None, *, embed=..., embeds=..., file=..., files=..., allowed_mentions=..., view=..., components=..., tts=False, ephemeral=False, suppress_embeds=False, delete_after=...)[source]¶
This function is a coroutine.
Sends a message using either
response.send_messageorfollowup.send.If the interaction hasn’t been responded to yet, this method will call
response.send_message. Otherwise, it will callfollowup.send.Note
This method does not return a
Messageobject. If you need a message object, useoriginal_response()to fetch it, or usefollowup.senddirectly instead of this method if you’re sending a followup message.- Parameters:
content (Optional[
str]) – The content of the message to send.embed (
Embed) – The rich embed for the content to send. This cannot be mixed with theembedsparameter.embeds (List[
Embed]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembedparameter.file (
File) – The file to upload. This cannot be mixed with thefilesparameter.files (List[
File]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefileparameter.allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. If this is passed, then the object is merged withClient.allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inClient.allowed_mentions. If no object is passed at all then the defaults given byClient.allowed_mentionsare used instead.tts (
bool) – Whether the message should be sent using text-to-speech.view (
disnake.ui.View) – The view to send with the message. This cannot be mixed withcomponents.components (Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]) –A list of components to send with the message. This cannot be mixed with
view.New in version 2.4.
ephemeral (
bool) – Whether the message should only be visible to the user who started the interaction. If a view is sent with an ephemeral message and it has no timeout set then the timeout is set to 15 minutes.suppress_embeds (
bool) –Whether to suppress embeds for the message. This hides all embeds from the UI if set to
True.New in version 2.5.
delete_after (
float) – If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.
- Raises:
HTTPException – Sending the message failed.
TypeError – You specified both
embedandembeds.ValueError – The length of
embedswas invalid.
ModalInteraction¶
- asyncdelete_original_message
- asyncdelete_original_response
- asyncedit_original_message
- asyncedit_original_response
- defis_expired
- asyncoriginal_message
- asyncoriginal_response
- asyncsend
- defwalk_raw_components
- class disnake.ModalInteraction[source]¶
Represents an interaction with a modal.
New in version 2.4.
- type¶
The interaction type.
- Type:
- guild_locale¶
The selected language of the interaction’s guild. This value is only meaningful in guilds with
COMMUNITYfeature and receives a default value otherwise. If the interaction was in a DM, then this value isNone.- Type:
Optional[
Locale]
- message¶
The message that this interaction’s modal originated from, if the modal was sent in response to a component interaction.
New in version 2.5.
- Type:
Optional[
Message]
- data¶
The wrapped interaction data.
- Type:
- original_message()[source]¶
An alias of
original_response().
- edit_original_message()[source]¶
An alias of
edit_original_response().
- delete_original_message()[source]¶
An alias of
delete_original_response().
- for ... in walk_raw_components()[source]¶
Returns a generator that yields raw component data from action rows one by one, as provided by Discord. This does not contain all fields of the components due to API limitations.
New in version 2.6.
- Return type:
Generator[
dict, None, None]
- text_values¶
Returns the text values the user has entered in the modal. This is a dict of the form
{custom_id: value}.
- property app_permissions[source]¶
The resolved permissions of the bot in the channel, including overwrites.
In a guild context, this is provided directly by Discord.
In a non-guild context this will be an instance of
Permissions.private_channel().New in version 2.6.
- Type:
- property bot[source]¶
The bot handling the interaction.
Only applicable when used with
Bot. This is an alias forclient.- Type:
- channel¶
The channel the interaction was sent from.
Note that due to a Discord limitation, threads that the bot cannot access and DM channels are not resolved since there is no data to complete them. These are
PartialMessageableinstead.If you want to compute the interaction author’s or bot’s permissions in the channel, consider using
permissionsorapp_permissionsinstead.- Type:
Union[
abc.GuildChannel,Thread,PartialMessageable]
- await delete_original_response(*, delay=None)[source]¶
This function is a coroutine.
Deletes the original interaction response message.
This is a lower level interface to
InteractionMessage.delete()in case you do not want to fetch the message and save an HTTP request.Changed in version 2.6: This function was renamed from
delete_original_message.- Parameters:
delay (
float) – If provided, the number of seconds to wait in the background before deleting the original response message. If the deletion fails, then it is silently ignored.- Raises:
HTTPException – Deleting the message failed.
Forbidden – Deleted a message that is not yours.
- await edit_original_response(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., view=..., components=..., allowed_mentions=None)[source]¶
This function is a coroutine.
Edits the original, previously sent interaction response message.
This is a lower level interface to
InteractionMessage.edit()in case you do not want to fetch the message and save an HTTP request.This method is also the only way to edit the original response if the message sent was ephemeral.
Note
If the original response message has embeds with images that were created from local files (using the
fileparameter withEmbed.set_image()orEmbed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by settingfile/files/attachments, or adding an embed with local files).Changed in version 2.6: This function was renamed from
edit_original_message.- Parameters:
content (Optional[
str]) – The content to edit the message with, orNoneto clear it.embed (Optional[
Embed]) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.embeds (List[
Embed]) – The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with theembedparameter. To remove all embeds[]should be passed.file (
File) – The file to upload. This cannot be mixed with thefilesparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.files (List[
File]) – A list of files to upload. This cannot be mixed with thefileparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.attachments (Optional[List[
Attachment]]) –A list of attachments to keep in the message. If
[]orNoneis passed then all existing attachments are removed. Keeps existing attachments if not provided.New in version 2.2.
Changed in version 2.5: Supports passing
Noneto clear attachments.view (Optional[
View]) – The updated view to update this message with. This cannot be mixed withcomponents. IfNoneis passed then the view is removed.components (Optional[Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]]) –A list of components to update this message with. This cannot be mixed with
view. IfNoneis passed then the components are removed.New in version 2.4.
allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embedandembedsorfileandfilesValueError – The length of
embedswas invalid.
- Returns:
The newly edited message.
- Return type:
- expires_at¶
Returns the interaction’s expiration time in UTC.
This is exactly 15 minutes after the interaction was created.
New in version 2.5.
- Type:
- is_expired()[source]¶
Whether the interaction can still be used to make requests to Discord.
This does not take into account the 3 second limit for the initial response.
New in version 2.5.
- Return type:
- me¶
Union[
Member,ClientUser]: Similar toGuild.meexcept it may return theClientUserin private message contexts.
- await original_response()[source]¶
This function is a coroutine.
Fetches the original interaction response message associated with the interaction.
Here is a table with response types and their associated original response:
Response type
Original response
The message you sent
The message you edited
The message with thinking state (bot is thinking…)
Other response types
None
Repeated calls to this will return a cached value.
Changed in version 2.6: This function was renamed from
original_message.- Raises:
HTTPException – Fetching the original response message failed.
- Returns:
The original interaction response message.
- Return type:
- property permissions[source]¶
The resolved permissions of the member in the channel, including overwrites.
In a guild context, this is provided directly by Discord.
In a non-guild context this will be an instance of
Permissions.private_channel().- Type:
- response¶
Returns an object responsible for handling responding to the interaction.
A response can only be done once. If secondary messages need to be sent, consider using
followupinstead.- Type:
- await send(content=None, *, embed=..., embeds=..., file=..., files=..., allowed_mentions=..., view=..., components=..., tts=False, ephemeral=False, suppress_embeds=False, delete_after=...)[source]¶
This function is a coroutine.
Sends a message using either
response.send_messageorfollowup.send.If the interaction hasn’t been responded to yet, this method will call
response.send_message. Otherwise, it will callfollowup.send.Note
This method does not return a
Messageobject. If you need a message object, useoriginal_response()to fetch it, or usefollowup.senddirectly instead of this method if you’re sending a followup message.- Parameters:
content (Optional[
str]) – The content of the message to send.embed (
Embed) – The rich embed for the content to send. This cannot be mixed with theembedsparameter.embeds (List[
Embed]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembedparameter.file (
File) – The file to upload. This cannot be mixed with thefilesparameter.files (List[
File]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefileparameter.allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. If this is passed, then the object is merged withClient.allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set inClient.allowed_mentions. If no object is passed at all then the defaults given byClient.allowed_mentionsare used instead.tts (
bool) – Whether the message should be sent using text-to-speech.view (
disnake.ui.View) – The view to send with the message. This cannot be mixed withcomponents.components (Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]) –A list of components to send with the message. This cannot be mixed with
view.New in version 2.4.
ephemeral (
bool) – Whether the message should only be visible to the user who started the interaction. If a view is sent with an ephemeral message and it has no timeout set then the timeout is set to 15 minutes.suppress_embeds (
bool) –Whether to suppress embeds for the message. This hides all embeds from the UI if set to
True.New in version 2.5.
delete_after (
float) – If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.
- Raises:
HTTPException – Sending the message failed.
TypeError – You specified both
embedandembeds.ValueError – The length of
embedswas invalid.
InteractionResponse¶
- asyncautocomplete
- asyncdefer
- asyncedit_message
- defis_done
- asyncpong
- asyncsend_message
- asyncsend_modal
- class disnake.InteractionResponse[source]¶
Represents a Discord interaction response.
This type can be accessed through
Interaction.response.New in version 2.0.
- property type[source]¶
If a response was successfully made, this is the type of the response.
New in version 2.6.
- Type:
Optional[
InteractionResponseType]
- is_done()[source]¶
Whether an interaction response has been done before.
An interaction can only be responded to once.
- Return type:
- await defer(*, with_message=..., ephemeral=...)[source]¶
This function is a coroutine.
Defers the interaction response.
This is typically used when the interaction is acknowledged and a secondary action will be done later.
Changed in version 2.5: Raises
TypeErrorwhen an interaction cannot be deferred.- Parameters:
with_message (
bool) –Whether the response will be a separate message with thinking state (bot is thinking…). This only applies to interactions of type
InteractionType.component(defaultFalse) andInteractionType.modal_submit(defaultTrue).Truecorresponds to adeferred_channel_messageresponse type, whileFalsecorresponds todeferred_message_update.Note
Responses to interactions of type
InteractionType.application_commandmust defer using a message, i.e. this will effectively always beTruefor those.New in version 2.4.
Changed in version 2.6: Added support for setting this to
Falsein modal interactions.ephemeral (
bool) –Whether the deferred message will eventually be ephemeral. This applies to interactions of type
InteractionType.application_command, or when thewith_messageparameter isTrue.Defaults to
False.
- Raises:
HTTPException – Deferring the interaction failed.
InteractionResponded – This interaction has already been responded to before.
TypeError – This interaction cannot be deferred.
- await pong()[source]¶
This function is a coroutine.
Pongs the ping interaction.
This should rarely be used.
- Raises:
HTTPException – Ponging the interaction failed.
InteractionResponded – This interaction has already been responded to before.
- await send_message(content=None, *, embed=..., embeds=..., file=..., files=..., allowed_mentions=..., view=..., components=..., tts=False, ephemeral=False, suppress_embeds=False, delete_after=...)[source]¶
This function is a coroutine.
Responds to this interaction by sending a message.
- Parameters:
content (Optional[
str]) – The content of the message to send.embed (
Embed) – The rich embed for the content to send. This cannot be mixed with theembedsparameter.embeds (List[
Embed]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembedparameter.file (
File) – The file to upload. This cannot be mixed with thefilesparameter.files (List[
File]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefileparameter.allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message.view (
disnake.ui.View) – The view to send with the message. This cannot be mixed withcomponents.components (Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]) –A list of components to send with the message. This cannot be mixed with
view.New in version 2.4.
tts (
bool) – Whether the message should be sent using text-to-speech.ephemeral (
bool) – Whether the message should only be visible to the user who started the interaction. If a view is sent with an ephemeral message and it has no timeout set then the timeout is set to 15 minutes.delete_after (
float) – If provided, the number of seconds to wait in the background before deleting the message we just sent. If the deletion fails, then it is silently ignored.suppress_embeds (
bool) –Whether to suppress embeds for the message. This hides all embeds from the UI if set to
True.New in version 2.5.
- Raises:
HTTPException – Sending the message failed.
TypeError – You specified both
embedandembeds.ValueError – The length of
embedswas invalid.InteractionResponded – This interaction has already been responded to before.
- await edit_message(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., allowed_mentions=..., view=..., components=...)[source]¶
This function is a coroutine.
Responds to this interaction by editing the original message of a component interaction or modal interaction (if the modal was sent in response to a component interaction).
Changed in version 2.5: Now supports editing the original message of modal interactions that started from a component.
Note
If the original message has embeds with images that were created from local files (using the
fileparameter withEmbed.set_image()orEmbed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by settingfile/files/attachments, or adding an embed with local files).- Parameters:
content (Optional[
str]) – The new content to replace the message with.Noneremoves the content.embed (Optional[
Embed]) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.embeds (List[
Embed]) – The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with theembedparameter. To remove all embeds[]should be passed.file (
File) –The file to upload. This cannot be mixed with the
filesparameter. Files will be appended to the message.New in version 2.2.
files (List[
File]) –A list of files to upload. This cannot be mixed with the
fileparameter. Files will be appended to the message.New in version 2.2.
attachments (Optional[List[
Attachment]]) –A list of attachments to keep in the message. If
[]orNoneis passed then all existing attachments are removed. Keeps existing attachments if not provided.New in version 2.4.
Changed in version 2.5: Supports passing
Noneto clear attachments.allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message.view (Optional[
View]) – The updated view to update this message with. This cannot be mixed withcomponents. IfNoneis passed then the view is removed.components (Optional[Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]]) –A list of components to update this message with. This cannot be mixed with
view. IfNoneis passed then the components are removed.New in version 2.4.
- Raises:
HTTPException – Editing the message failed.
TypeError – You specified both
embedandembeds.InteractionResponded – This interaction has already been responded to before.
- await autocomplete(*, choices)[source]¶
This function is a coroutine.
Responds to this interaction by displaying a list of possible autocomplete results. Only works for autocomplete interactions.
- Parameters:
choices (Union[List[
OptionChoice], List[Union[str,int]], Dict[str, Union[str,int]]]) – The list of choices to suggest.- Raises:
HTTPException – Autocomplete response has failed.
InteractionResponded – This interaction has already been responded to before.
- await send_modal(modal=None, *, title=None, custom_id=None, components=None)[source]¶
This function is a coroutine.
Responds to this interaction by displaying a modal.
New in version 2.4.
Note
Not passing the
modalparameter here will not register a callback, and aon_modal_submit()interaction will need to be handled manually.- Parameters:
modal (
Modal) – The modal to display. This cannot be mixed with thetitle,custom_idandcomponentsparameters.title (
str) – The title of the modal. This cannot be mixed with themodalparameter.custom_id (
str) – The ID of the modal that gets received during an interaction. This cannot be mixed with themodalparameter.components (Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]) – The components to display in the modal. A maximum of 5. This cannot be mixed with themodalparameter.
- Raises:
TypeError – Cannot mix the
modalparameter and thetitle,custom_id,componentsparameters.ValueError – Maximum number of components (5) exceeded.
HTTPException – Displaying the modal failed.
ModalChainNotSupported – This interaction cannot be responded with a modal.
InteractionResponded – This interaction has already been responded to before.
InteractionMessage¶
- attachments
- author
- channel
- channel_mentions
- clean_content
- components
- content
- created_at
- edited_at
- embeds
- flags
- guild
- id
- interaction
- jump_url
- mention_everyone
- mentions
- pinned
- raw_channel_mentions
- raw_mentions
- raw_role_mentions
- reactions
- reference
- role_mentions
- stickers
- system_content
- thread
- type
- webhook_id
- asyncadd_reaction
- asyncclear_reaction
- asyncclear_reactions
- asynccreate_thread
- asyncdelete
- asyncedit
- defis_system
- asyncpin
- asyncpublish
- asyncremove_reaction
- asyncreply
- defto_reference
- asyncunpin
- class disnake.InteractionMessage[source]¶
Represents the original interaction response message.
This allows you to edit or delete the message associated with the interaction response. To retrieve this object see
Interaction.original_response().This inherits from
disnake.Messagewith changes toedit()anddelete()to work.New in version 2.0.
- type¶
The type of message.
- Type:
- channel¶
The channel that the message was sent from. Could be a
DMChannelorGroupChannelif it’s a private message.- Type:
Union[
TextChannel,VoiceChannel,Thread,DMChannel,GroupChannel,PartialMessageable]
- reference¶
The message that this message references. This is only applicable to message replies.
- Type:
Optional[
MessageReference]
- interaction¶
The interaction that this message references. This exists only when the message is a response to an interaction without an existing message.
New in version 2.1.
- Type:
Optional[
InteractionReference]
- mention_everyone¶
Specifies if the message mentions everyone.
Note
This does not check if the
@everyoneor the@heretext is in the message itself. Rather this boolean indicates if either the@everyoneor the@heretext is in the message and it did end up mentioning.- Type:
- mentions¶
A list of
Memberthat were mentioned. If the message is in a private message then the list will be ofUserinstead.Warning
The order of the mentions list is not in any particular order so you should not rely on it. This is a Discord limitation, not one with the library.
- Type:
List[
abc.User]
- role_mentions¶
A list of
Rolethat were mentioned. If the message is in a private message then the list is always empty.- Type:
List[
Role]
- attachments¶
A list of attachments given to a message.
- Type:
List[
Attachment]
- flags¶
Extra features of the message.
- Type:
- reactions¶
Reactions to a message. Reactions can be either custom emoji or standard unicode emoji.
- Type:
List[
Reaction]
- stickers¶
A list of sticker items given to the message.
- Type:
List[
StickerItem]
- await add_reaction(emoji)[source]¶
This function is a coroutine.
Adds a reaction to the message.
The emoji may be a unicode emoji or a custom guild
Emoji.You must have the
read_message_historypermission to use this. If nobody else has reacted to the message using this emoji, theadd_reactionspermission is required.Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
emoji (Union[
Emoji,Reaction,PartialEmoji,str]) – The emoji to react with.- Raises:
HTTPException – Adding the reaction failed.
Forbidden – You do not have the proper permissions to react to the message.
NotFound – The emoji you specified was not found.
TypeError – The emoji parameter is invalid.
- channel_mentions¶
A list of
abc.GuildChannelthat were mentioned. If the message is in a private message then the list is always empty.- Type:
List[
abc.GuildChannel]
- clean_content¶
A property that returns the content in a “cleaned up” manner. This basically means that mentions are transformed into the way the client shows it. e.g.
<#id>will transform into#name.This will also transform @everyone and @here mentions into non-mentions.
Note
This does not affect markdown. If you want to escape or remove markdown then use
utils.escape_markdown()orutils.remove_markdown()respectively, along with this function.- Type:
- await clear_reaction(emoji)[source]¶
This function is a coroutine.
Clears a specific reaction from the message.
The emoji may be a unicode emoji or a custom guild
Emoji.You need the
manage_messagespermission to use this.New in version 1.3.
Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
emoji (Union[
Emoji,Reaction,PartialEmoji,str]) – The emoji to clear.- Raises:
HTTPException – Clearing the reaction failed.
Forbidden – You do not have the proper permissions to clear the reaction.
NotFound – The emoji you specified was not found.
TypeError – The emoji parameter is invalid.
- await clear_reactions()[source]¶
This function is a coroutine.
Removes all the reactions from the message.
You need the
manage_messagespermission to use this.- Raises:
HTTPException – Removing the reactions failed.
Forbidden – You do not have the proper permissions to remove all the reactions.
- await create_thread(*, name, auto_archive_duration=None, slowmode_delay=None, reason=None)[source]¶
This function is a coroutine.
Creates a public thread from this message.
You must have
create_public_threadsin order to create a public thread from a message.The channel this message belongs in must be a
TextChannel.New in version 2.0.
Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
name (
str) – The name of the thread.auto_archive_duration (Union[
int,ThreadArchiveDuration]) – The duration in minutes before a thread is automatically archived for inactivity. If not provided, the channel’s default auto archive duration is used. Must be one of60,1440,4320, or10080.slowmode_delay (
int) –Specifies the slowmode rate limit for users in this thread, in seconds. A value of
0disables slowmode. The maximum value possible is21600. If not provided, slowmode is disabled.New in version 2.3.
reason (Optional[
str]) –The reason for creating the thread. Shows up on the audit log.
New in version 2.5.
- Raises:
Forbidden – You do not have permissions to create a thread.
HTTPException – Creating the thread failed.
TypeError – This message does not have guild info attached.
- Returns:
The created thread.
- Return type:
- property edited_at[source]¶
An aware UTC datetime object containing the edited time of the message.
- Type:
Optional[
datetime.datetime]
- is_system()[source]¶
Whether the message is a system message.
A system message is a message that is constructed entirely by the Discord API in response to something.
New in version 1.3.
- Return type:
- await pin(*, reason=None)[source]¶
This function is a coroutine.
Pins the message.
You must have the
manage_messagespermission to do this in a non-private channel context.- Parameters:
reason (Optional[
str]) –The reason for pinning the message. Shows up on the audit log.
New in version 1.4.
- Raises:
Forbidden – You do not have permissions to pin the message.
NotFound – The message or channel was not found or deleted.
HTTPException – Pinning the message failed, probably due to the channel having more than 50 pinned messages.
- await publish()[source]¶
This function is a coroutine.
Publishes this message to your announcement channel.
You must have the
send_messagespermission to do this.If the message is not your own then the
manage_messagespermission is also needed.- Raises:
Forbidden – You do not have the proper permissions to publish this message.
HTTPException – Publishing the message failed.
- raw_channel_mentions¶
A property that returns an array of channel IDs matched with the syntax of
<#channel_id>in the message content.- Type:
List[
int]
- raw_mentions¶
A property that returns an array of user IDs matched with the syntax of
<@user_id>in the message content.This allows you to receive the user IDs of mentioned users even in a private message context.
- Type:
List[
int]
- raw_role_mentions¶
A property that returns an array of role IDs matched with the syntax of
<@&role_id>in the message content.- Type:
List[
int]
- await remove_reaction(emoji, member)[source]¶
This function is a coroutine.
Removes a reaction by the member from the message.
The emoji may be a unicode emoji or a custom guild
Emoji.If the reaction is not your own (i.e.
memberparameter is not you) then themanage_messagespermission is needed.The
memberparameter must represent a member and meet theabc.Snowflakeabc.Changed in version 2.6: Raises
TypeErrorinstead ofInvalidArgument.- Parameters:
emoji (Union[
Emoji,Reaction,PartialEmoji,str]) – The emoji to remove.member (
abc.Snowflake) – The member for which to remove the reaction.
- Raises:
HTTPException – Removing the reaction failed.
Forbidden – You do not have the proper permissions to remove the reaction.
NotFound – The member or emoji you specified was not found.
TypeError – The emoji parameter is invalid.
- await reply(content=None, *, fail_if_not_exists=True, **kwargs)[source]¶
This function is a coroutine.
A shortcut method to
abc.Messageable.send()to reply to theMessage.New in version 1.6.
Changed in version 2.3: Added
fail_if_not_existskeyword argument. Defaults toTrue.Changed in version 2.6: Raises
TypeErrororValueErrorinstead ofInvalidArgument.- Parameters:
fail_if_not_exists (
bool) –Whether replying using the message reference should raise
HTTPExceptionif the message no longer exists or Discord could not fetch the message.New in version 2.3.
- Raises:
HTTPException – Sending the message failed.
Forbidden – You do not have the proper permissions to send the message.
TypeError – You specified both
embedandembeds, orfileandfiles, orviewandcomponents.ValueError – The
filesorembedslist is too large.
- Returns:
The message that was sent.
- Return type:
- system_content¶
A property that returns the content that is rendered regardless of the
Message.type.In the case of
MessageType.defaultandMessageType.reply, this just returns the regularMessage.content. Otherwise this returns an English message denoting the contents of the system message.If the message type is unrecognised this method will return
None.- Type:
Optional[
str]
- property thread[source]¶
The thread started from this message.
Noneif no thread has been started.New in version 2.4.
- Type:
Optional[
Thread]
- to_reference(*, fail_if_not_exists=True)[source]¶
Creates a
MessageReferencefrom the current message.New in version 1.6.
- Parameters:
fail_if_not_exists (
bool) –Whether replying using the message reference should raise
HTTPExceptionif the message no longer exists or Discord could not fetch the message.New in version 1.7.
- Returns:
The reference to this message.
- Return type:
- await unpin(*, reason=None)[source]¶
This function is a coroutine.
Unpins the message.
You must have the
manage_messagespermission to do this in a non-private channel context.- Parameters:
reason (Optional[
str]) –The reason for unpinning the message. Shows up on the audit log.
New in version 1.4.
- Raises:
Forbidden – You do not have permissions to unpin the message.
NotFound – The message or channel was not found or deleted.
HTTPException – Unpinning the message failed.
- await edit(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., allowed_mentions=..., view=..., components=...)[source]¶
This function is a coroutine.
Edits the message.
Note
If the original message has embeds with images that were created from local files (using the
fileparameter withEmbed.set_image()orEmbed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by settingfile/files/attachments, or adding an embed with local files).- Parameters:
content (Optional[
str]) – The content to edit the message with, orNoneto clear it.embed (Optional[
Embed]) – The new embed to replace the original with. This cannot be mixed with theembedsparameter. Could beNoneto remove the embed.embeds (List[
Embed]) – The new embeds to replace the original with. Must be a maximum of 10. This cannot be mixed with theembedparameter. To remove all embeds[]should be passed.file (
File) – The file to upload. This cannot be mixed with thefilesparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.files (List[
File]) – A list of files to upload. This cannot be mixed with thefileparameter. Files will be appended to the message, see theattachmentsparameter to remove/replace existing files.attachments (Optional[List[
Attachment]]) –A list of attachments to keep in the message. If
[]orNoneis passed then all existing attachments are removed. Keeps existing attachments if not provided.New in version 2.2.
Changed in version 2.5: Supports passing
Noneto clear attachments.view (Optional[
View]) – The updated view to update this message with. This cannot be mixed withcomponents. IfNoneis passed then the view is removed.components (Optional[Union[
disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[Union[disnake.ui.ActionRow,disnake.ui.WrappedComponent, List[disnake.ui.WrappedComponent]]]]]) –A list of components to update this message with. This cannot be mixed with
view. IfNoneis passed then the components are removed.New in version 2.4.
allowed_mentions (
AllowedMentions) – Controls the mentions being processed in this message. Seeabc.Messageable.send()for more information.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embedandembedsorfileandfilesValueError – The length of
embedswas invalid.
- Returns:
The newly edited message.
- Return type:
- await delete(*, delay=None)[source]¶
This function is a coroutine.
Deletes the message.
- Parameters:
delay (Optional[
float]) – If provided, the number of seconds to wait before deleting the message. The waiting is done in the background and deletion failures are ignored.- Raises:
Forbidden – You do not have proper permissions to delete the message.
NotFound – The message was deleted already.
HTTPException – Deleting the message failed.
InteractionReference¶
- class disnake.InteractionReference(*, state, data)[source]¶
This class is a Discord Model.
Represents an interaction being referenced in a message.
This means responses to message components do not include this property, instead including a message reference object as components always exist on preexisting messages.
New in version 2.1.
- type¶
The type of interaction.
- Type:
- name¶
The name of the application command, including group and subcommand name if applicable (separated by spaces).
Note
For interaction references created before July 18th, 2022, this will not include group or subcommand names.
- Type:
Data Classes¶
ApplicationCommandInteractionData¶
- class disnake.ApplicationCommandInteractionData[source]¶
Represents the data of an interaction with an application command.
New in version 2.1.
- type¶
The application command type.
- Type:
- resolved¶
All resolved objects related to this interaction.
- options¶
A list of options from the API.
- Type:
- target¶
The user or message targetted by a user or message command
ApplicationCommandInteractionDataOption¶
- class disnake.ApplicationCommandInteractionDataOption[source]¶
This class represents the structure of an interaction data option from the API.
- type¶
The option’s type.
- Type:
- value¶
The option’s value.
- Type:
Any
- options¶
The list of options of this option. Only exists for subcommands and groups.
- Type:
ApplicationCommandInteractionDataResolved¶
- class disnake.ApplicationCommandInteractionDataResolved[source]¶
Represents the resolved data related to an interaction with an application command.
New in version 2.1.
- members¶
A mapping of IDs to partial members (
deafandmuteattributes are missing).
- channels¶
A mapping of IDs to partial channels (only
id,nameandpermissionsare included, threads also havethread_metadataandparent_id).- Type:
Dict[
int, Channel]
- attachments¶
A mapping of IDs to attachments.
New in version 2.4.
- Type:
Dict[
int,Attachment]
MessageInteractionData¶
ModalInteractionData¶
Enumerations¶
InteractionType¶
- class disnake.InteractionType[source]¶
This class is an Enumeration.
Specifies the type of
Interaction.New in version 2.0.
- ping¶
Represents Discord pinging to see if the interaction response server is alive.
- application_command¶
Represents an application command interaction.
- component¶
Represents a component based interaction, i.e. using the Discord Bot UI Kit.
- application_command_autocomplete¶
Represents an application command autocomplete interaction.
- modal_submit¶
Represents a modal submit interaction.
InteractionResponseType¶
- class disnake.InteractionResponseType[source]¶
This class is an Enumeration.
Specifies the response type for the interaction.
New in version 2.0.
- pong¶
Pongs the interaction when given a ping.
See also
InteractionResponse.pong()
- channel_message¶
Respond to the interaction with a message.
See also
InteractionResponse.send_message()
- deferred_channel_message¶
Responds to the interaction with a message at a later time.
See also
InteractionResponse.defer()
- deferred_message_update¶
Acknowledges the component interaction with a promise that the message will update later (though there is no need to actually update the message).
See also
InteractionResponse.defer()
- message_update¶
Responds to the interaction by editing the message.
See also
InteractionResponse.edit_message()
- application_command_autocomplete_result¶
Responds to the autocomplete interaction with suggested choices.
See also
InteractionResponse.autocomplete()
- modal¶
Responds to the interaction by displaying a modal.
See also
InteractionResponse.send_modal()
Events¶
See all related events!