Interactions¶
This section documents everything related to interactions, which are used for communication between user and client. Common examples 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
COMMUNITY
feature 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
]
- channel¶
The channel the interaction was sent from.
Note that due to a Discord limitation, DM channels may not contain recipient information. Unknown channel types will be
PartialMessageable
.Changed in version 2.10: If the interaction was sent from a thread and the bot cannot normally access the thread, this is now a proper
Thread
object. Private channels are now properDMChannel
/GroupChannel
objects instead ofPartialMessageable
.Note
If you want to compute the interaction author’s or bot’s permissions in the channel, consider using
permissions
orapp_permissions
.- Type:
Union[
abc.GuildChannel
,Thread
,abc.PrivateChannel
,PartialMessageable
]
- entitlements¶
The entitlements for the invoking user and guild, representing access to an application subscription.
New in version 2.10.
- Type:
List[
Entitlement
]
- 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 user[source]¶
The user or member that sent the interaction. There is an alias for this named
author
.
- me¶
Union[
Member
,ClientUser
]: Similar toGuild.me
except it may return theClientUser
in private message contexts.
- 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
followup
instead.- 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.
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=..., poll=..., suppress_embeds=..., flags=..., allowed_mentions=None, delete_after=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
file
parameter 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, orNone
to clear it.embed (Optional[
Embed
]) – The new embed to replace the original with. This cannot be mixed with theembeds
parameter. Could beNone
to 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 theembed
parameter. To remove all embeds[]
should be passed.file (
File
) – The file to upload. This cannot be mixed with thefiles
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.files (List[
File
]) – A list of files to upload. This cannot be mixed with thefile
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.attachments (Optional[List[
Attachment
]]) –A list of attachments to keep in the message. If
[]
orNone
is 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
None
to clear attachments.view (Optional[
View
]) – The updated view to update this message with. This cannot be mixed withcomponents
. IfNone
is 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
. IfNone
is passed then the components are removed.New in version 2.4.
poll (
Poll
) –A poll. This can only be sent after a defer. If not used after a defer the discord API ignore the field.
New in version 2.10.
allowed_mentions (
AllowedMentions
) – Controls the mentions being processed in this message. Seeabc.Messageable.send()
for more information.suppress_embeds (
bool
) –Whether to suppress embeds for the message. This hides all the embeds from the UI if set to
True
. If set toFalse
, this brings the embeds back if they were suppressed.New in version 2.7.
flags (
MessageFlags
) –The new flags to set for this message. Overrides existing flags. Only
suppress_embeds
is supported.If parameter
suppress_embeds
is provided, that will override the setting ofMessageFlags.suppress_embeds
.New in version 2.9.
delete_after (Optional[
float
]) –If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).New in version 2.10.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embed
andembeds
orfile
andfiles
ValueError – The length of
embeds
was 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 (Optional[
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.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).- 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=..., suppress_embeds=..., flags=..., delete_after=..., poll=...)[source]¶
This function is a coroutine.
Sends a message using either
response.send_message
orfollowup.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
Message
object. If you need a message object, useoriginal_response()
to fetch it, or usefollowup.send
directly 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 theembeds
parameter.embeds (List[
Embed
]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembed
parameter.file (
File
) – The file to upload. This cannot be mixed with thefiles
parameter.files (List[
File
]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefile
parameter.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_mentions
are 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 the embeds from the UI if set to
True
.New in version 2.5.
flags (
MessageFlags
) –The flags to set for this message. Only
suppress_embeds
,ephemeral
andsuppress_notifications
are supported.If parameters
suppress_embeds
orephemeral
are provided, they will override the corresponding setting of thisflags
parameter.New in version 2.9.
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.
Can be up to 15 minutes after the interaction was created (see also
expires_at
/is_expired
).Changed in version 2.7: Added support for ephemeral responses.
poll (
Poll
) –The poll to send with the message.
New in version 2.10.
- Raises:
HTTPException – Sending the message failed.
TypeError – You specified both
embed
andembeds
.ValueError – The length of
embeds
was 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:
- channel¶
The channel the interaction was sent from.
Note that due to a Discord limitation, DM channels may not contain recipient information. Unknown channel types will be
PartialMessageable
.Changed in version 2.10: If the interaction was sent from a thread and the bot cannot normally access the thread, this is now a proper
Thread
object. Private channels are now properDMChannel
/GroupChannel
objects instead ofPartialMessageable
.Note
If you want to compute the interaction author’s or bot’s permissions in the channel, consider using
permissions
orapp_permissions
.- Type:
Union[
abc.GuildChannel
,Thread
,abc.PrivateChannel
,PartialMessageable
]
- guild_locale¶
The selected language of the interaction’s guild. This value is only meaningful in guilds with
COMMUNITY
feature 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
]
- entitlements¶
The entitlements for the invoking user and guild, representing access to an application subscription.
New in version 2.10.
- Type:
List[
Entitlement
]
- 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:
- 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 (Optional[
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.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).- 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=..., poll=..., suppress_embeds=..., flags=..., allowed_mentions=None, delete_after=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
file
parameter 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, orNone
to clear it.embed (Optional[
Embed
]) – The new embed to replace the original with. This cannot be mixed with theembeds
parameter. Could beNone
to 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 theembed
parameter. To remove all embeds[]
should be passed.file (
File
) – The file to upload. This cannot be mixed with thefiles
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.files (List[
File
]) – A list of files to upload. This cannot be mixed with thefile
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.attachments (Optional[List[
Attachment
]]) –A list of attachments to keep in the message. If
[]
orNone
is 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
None
to clear attachments.view (Optional[
View
]) – The updated view to update this message with. This cannot be mixed withcomponents
. IfNone
is 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
. IfNone
is passed then the components are removed.New in version 2.4.
poll (
Poll
) –A poll. This can only be sent after a defer. If not used after a defer the discord API ignore the field.
New in version 2.10.
allowed_mentions (
AllowedMentions
) – Controls the mentions being processed in this message. Seeabc.Messageable.send()
for more information.suppress_embeds (
bool
) –Whether to suppress embeds for the message. This hides all the embeds from the UI if set to
True
. If set toFalse
, this brings the embeds back if they were suppressed.New in version 2.7.
flags (
MessageFlags
) –The new flags to set for this message. Overrides existing flags. Only
suppress_embeds
is supported.If parameter
suppress_embeds
is provided, that will override the setting ofMessageFlags.suppress_embeds
.New in version 2.9.
delete_after (Optional[
float
]) –If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).New in version 2.10.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embed
andembeds
orfile
andfiles
ValueError – The length of
embeds
was 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.me
except it may return theClientUser
in private message contexts.
- await original_response()[source]¶
This function is a coroutine.
Fetches the original interaction response message associated with the interaction.
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
followup
instead.- Type:
- await send(content=None, *, embed=..., embeds=..., file=..., files=..., allowed_mentions=..., view=..., components=..., tts=False, ephemeral=..., suppress_embeds=..., flags=..., delete_after=..., poll=...)[source]¶
This function is a coroutine.
Sends a message using either
response.send_message
orfollowup.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
Message
object. If you need a message object, useoriginal_response()
to fetch it, or usefollowup.send
directly 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 theembeds
parameter.embeds (List[
Embed
]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembed
parameter.file (
File
) – The file to upload. This cannot be mixed with thefiles
parameter.files (List[
File
]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefile
parameter.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_mentions
are 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 the embeds from the UI if set to
True
.New in version 2.5.
flags (
MessageFlags
) –The flags to set for this message. Only
suppress_embeds
,ephemeral
andsuppress_notifications
are supported.If parameters
suppress_embeds
orephemeral
are provided, they will override the corresponding setting of thisflags
parameter.New in version 2.9.
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.
Can be up to 15 minutes after the interaction was created (see also
expires_at
/is_expired
).Changed in version 2.7: Added support for ephemeral responses.
poll (
Poll
) –The poll to send with the message.
New in version 2.10.
- Raises:
HTTPException – Sending the message failed.
TypeError – You specified both
embed
andembeds
.ValueError – The length of
embeds
was invalid.
GuildCommandInteraction¶
- class disnake.GuildCommandInteraction[source]¶
An
ApplicationCommandInteraction
subclass, primarily meant for annotations.This prevents the command from being invoked in DMs by automatically setting
ApplicationCommand.dm_permission
toFalse
for 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
ApplicationCommandInteraction
subclass 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
ApplicationCommandInteraction
subclass 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:
- channel¶
The channel the interaction was sent from.
Note that due to a Discord limitation, DM channels may not contain recipient information. Unknown channel types will be
PartialMessageable
.Changed in version 2.10: If the interaction was sent from a thread and the bot cannot normally access the thread, this is now a proper
Thread
object. Private channels are now properDMChannel
/GroupChannel
objects instead ofPartialMessageable
.Note
If you want to compute the interaction author’s or bot’s permissions in the channel, consider using
permissions
orapp_permissions
.- Type:
Union[
abc.GuildChannel
,Thread
,abc.PrivateChannel
,PartialMessageable
]
- guild_locale¶
The selected language of the interaction’s guild. This value is only meaningful in guilds with
COMMUNITY
feature 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
]
- entitlements¶
The entitlements for the invoking user and guild, representing access to an application subscription.
New in version 2.10.
- Type:
List[
Entitlement
]
- 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()
.
- property values[source]¶
The values the user selected.
For select menus of type
string_select
, these are just the string values the user selected. For other select menu types, these are the IDs of the selected entities.See also
resolved_values
.- Type:
Optional[List[
str
]]
- resolved_values¶
The (resolved) values the user selected.
For select menus of type
string_select
, this is equivalent tovalues
. For other select menu types, these are full objects corresponding to the selected entities.New in version 2.7.
- Type:
Optional[Sequence[
str
,Member
,User
,Role
, Union[abc.GuildChannel
,Thread
,PartialMessageable
]]]
- 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:
- 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 (Optional[
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.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).- 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=..., poll=..., suppress_embeds=..., flags=..., allowed_mentions=None, delete_after=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
file
parameter 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, orNone
to clear it.embed (Optional[
Embed
]) – The new embed to replace the original with. This cannot be mixed with theembeds
parameter. Could beNone
to 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 theembed
parameter. To remove all embeds[]
should be passed.file (
File
) – The file to upload. This cannot be mixed with thefiles
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.files (List[
File
]) – A list of files to upload. This cannot be mixed with thefile
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.attachments (Optional[List[
Attachment
]]) –A list of attachments to keep in the message. If
[]
orNone
is 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
None
to clear attachments.view (Optional[
View
]) – The updated view to update this message with. This cannot be mixed withcomponents
. IfNone
is 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
. IfNone
is passed then the components are removed.New in version 2.4.
poll (
Poll
) –A poll. This can only be sent after a defer. If not used after a defer the discord API ignore the field.
New in version 2.10.
allowed_mentions (
AllowedMentions
) – Controls the mentions being processed in this message. Seeabc.Messageable.send()
for more information.suppress_embeds (
bool
) –Whether to suppress embeds for the message. This hides all the embeds from the UI if set to
True
. If set toFalse
, this brings the embeds back if they were suppressed.New in version 2.7.
flags (
MessageFlags
) –The new flags to set for this message. Overrides existing flags. Only
suppress_embeds
is supported.If parameter
suppress_embeds
is provided, that will override the setting ofMessageFlags.suppress_embeds
.New in version 2.9.
delete_after (Optional[
float
]) –If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).New in version 2.10.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embed
andembeds
orfile
andfiles
ValueError – The length of
embeds
was 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.me
except it may return theClientUser
in private message contexts.
- await original_response()[source]¶
This function is a coroutine.
Fetches the original interaction response message associated with the interaction.
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
followup
instead.- Type:
- await send(content=None, *, embed=..., embeds=..., file=..., files=..., allowed_mentions=..., view=..., components=..., tts=False, ephemeral=..., suppress_embeds=..., flags=..., delete_after=..., poll=...)[source]¶
This function is a coroutine.
Sends a message using either
response.send_message
orfollowup.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
Message
object. If you need a message object, useoriginal_response()
to fetch it, or usefollowup.send
directly 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 theembeds
parameter.embeds (List[
Embed
]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembed
parameter.file (
File
) – The file to upload. This cannot be mixed with thefiles
parameter.files (List[
File
]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefile
parameter.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_mentions
are 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 the embeds from the UI if set to
True
.New in version 2.5.
flags (
MessageFlags
) –The flags to set for this message. Only
suppress_embeds
,ephemeral
andsuppress_notifications
are supported.If parameters
suppress_embeds
orephemeral
are provided, they will override the corresponding setting of thisflags
parameter.New in version 2.9.
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.
Can be up to 15 minutes after the interaction was created (see also
expires_at
/is_expired
).Changed in version 2.7: Added support for ephemeral responses.
poll (
Poll
) –The poll to send with the message.
New in version 2.10.
- Raises:
HTTPException – Sending the message failed.
TypeError – You specified both
embed
andembeds
.ValueError – The length of
embeds
was 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:
- channel¶
The channel the interaction was sent from.
Note that due to a Discord limitation, DM channels may not contain recipient information. Unknown channel types will be
PartialMessageable
.Changed in version 2.10: If the interaction was sent from a thread and the bot cannot normally access the thread, this is now a proper
Thread
object. Private channels are now properDMChannel
/GroupChannel
objects instead ofPartialMessageable
.Note
If you want to compute the interaction author’s or bot’s permissions in the channel, consider using
permissions
orapp_permissions
.- Type:
Union[
abc.GuildChannel
,Thread
,abc.PrivateChannel
,PartialMessageable
]
- guild_locale¶
The selected language of the interaction’s guild. This value is only meaningful in guilds with
COMMUNITY
feature and receives a default value otherwise. If the interaction was in a DM, then this value isNone
.- Type:
Optional[
Locale
]
- entitlements¶
The entitlements for the invoking user and guild, representing access to an application subscription.
New in version 2.10.
- Type:
List[
Entitlement
]
- data¶
The wrapped interaction data.
- Type:
- 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
]
- 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:
- 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 (Optional[
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.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).- 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=..., poll=..., suppress_embeds=..., flags=..., allowed_mentions=None, delete_after=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
file
parameter 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, orNone
to clear it.embed (Optional[
Embed
]) – The new embed to replace the original with. This cannot be mixed with theembeds
parameter. Could beNone
to 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 theembed
parameter. To remove all embeds[]
should be passed.file (
File
) – The file to upload. This cannot be mixed with thefiles
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.files (List[
File
]) – A list of files to upload. This cannot be mixed with thefile
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.attachments (Optional[List[
Attachment
]]) –A list of attachments to keep in the message. If
[]
orNone
is 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
None
to clear attachments.view (Optional[
View
]) – The updated view to update this message with. This cannot be mixed withcomponents
. IfNone
is 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
. IfNone
is passed then the components are removed.New in version 2.4.
poll (
Poll
) –A poll. This can only be sent after a defer. If not used after a defer the discord API ignore the field.
New in version 2.10.
allowed_mentions (
AllowedMentions
) – Controls the mentions being processed in this message. Seeabc.Messageable.send()
for more information.suppress_embeds (
bool
) –Whether to suppress embeds for the message. This hides all the embeds from the UI if set to
True
. If set toFalse
, this brings the embeds back if they were suppressed.New in version 2.7.
flags (
MessageFlags
) –The new flags to set for this message. Overrides existing flags. Only
suppress_embeds
is supported.If parameter
suppress_embeds
is provided, that will override the setting ofMessageFlags.suppress_embeds
.New in version 2.9.
delete_after (Optional[
float
]) –If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).New in version 2.10.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embed
andembeds
orfile
andfiles
ValueError – The length of
embeds
was 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.me
except it may return theClientUser
in private message contexts.
- await original_response()[source]¶
This function is a coroutine.
Fetches the original interaction response message associated with the interaction.
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
followup
instead.- Type:
- await send(content=None, *, embed=..., embeds=..., file=..., files=..., allowed_mentions=..., view=..., components=..., tts=False, ephemeral=..., suppress_embeds=..., flags=..., delete_after=..., poll=...)[source]¶
This function is a coroutine.
Sends a message using either
response.send_message
orfollowup.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
Message
object. If you need a message object, useoriginal_response()
to fetch it, or usefollowup.send
directly 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 theembeds
parameter.embeds (List[
Embed
]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembed
parameter.file (
File
) – The file to upload. This cannot be mixed with thefiles
parameter.files (List[
File
]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefile
parameter.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_mentions
are 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 the embeds from the UI if set to
True
.New in version 2.5.
flags (
MessageFlags
) –The flags to set for this message. Only
suppress_embeds
,ephemeral
andsuppress_notifications
are supported.If parameters
suppress_embeds
orephemeral
are provided, they will override the corresponding setting of thisflags
parameter.New in version 2.9.
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.
Can be up to 15 minutes after the interaction was created (see also
expires_at
/is_expired
).Changed in version 2.7: Added support for ephemeral responses.
poll (
Poll
) –The poll to send with the message.
New in version 2.10.
- Raises:
HTTPException – Sending the message failed.
TypeError – You specified both
embed
andembeds
.ValueError – The length of
embeds
was invalid.
InteractionResponse¶
- asyncautocomplete
- asyncdefer
- asyncedit_message
- defis_done
- asyncpong
- asyncrequire_premium
- 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
TypeError
when 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
).True
corresponds to adeferred_channel_message
response type, whileFalse
corresponds todeferred_message_update
.Note
Responses to interactions of type
InteractionType.application_command
must defer using a message, i.e. this will effectively always beTrue
for those.New in version 2.4.
Changed in version 2.6: Added support for setting this to
False
in modal interactions.ephemeral (
bool
) –Whether the deferred message will eventually be ephemeral. This applies to interactions of type
InteractionType.application_command
, or when thewith_message
parameter 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=..., suppress_embeds=..., flags=..., delete_after=..., poll=...)[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 theembeds
parameter.embeds (List[
Embed
]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with theembed
parameter.file (
File
) – The file to upload. This cannot be mixed with thefiles
parameter.files (List[
File
]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with thefile
parameter.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.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).Changed in version 2.7: Added support for ephemeral responses.
suppress_embeds (
bool
) –Whether to suppress embeds for the message. This hides all the embeds from the UI if set to
True
.New in version 2.5.
flags (
MessageFlags
) –The flags to set for this message. Only
suppress_embeds
,ephemeral
andsuppress_notifications
are supported.If parameters
suppress_embeds
orephemeral
are provided, they will override the corresponding setting of thisflags
parameter.New in version 2.9.
poll (
Poll
) –The poll to send with the message.
New in version 2.10.
- Raises:
HTTPException – Sending the message failed.
TypeError – You specified both
embed
andembeds
.ValueError – The length of
embeds
was invalid.InteractionResponded – This interaction has already been responded to before.
- await edit_message(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., allowed_mentions=..., view=..., components=..., delete_after=None)[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
file
parameter 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.None
removes the content.embed (Optional[
Embed
]) – The new embed to replace the original with. This cannot be mixed with theembeds
parameter. Could beNone
to 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 theembed
parameter. To remove all embeds[]
should be passed.file (
File
) –The file to upload. This cannot be mixed with the
files
parameter. 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
file
parameter. 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
[]
orNone
is 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
None
to 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
. IfNone
is 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
. IfNone
is passed then the components are removed.New in version 2.4.
delete_after (Optional[
float
]) –If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).New in version 2.10.
- Raises:
HTTPException – Editing the message failed.
TypeError – You specified both
embed
andembeds
.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[Sequence[
OptionChoice
], Sequence[Union[str
,int
,float
]], Mapping[str
, Union[str
,int
,float
]]]) – The 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
modal
parameter 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_id
andcomponents
parameters.title (
str
) – The title of the modal. This cannot be mixed with themodal
parameter.custom_id (
str
) – The ID of the modal that gets received during an interaction. This cannot be mixed with themodal
parameter.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 themodal
parameter.
- Raises:
TypeError – Cannot mix the
modal
parameter and thetitle
,custom_id
,components
parameters.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.
This function is a coroutine.
Responds to this interaction with a message containing an upgrade button.
Only available for applications with monetization enabled.
New in version 2.10.
Example
Require an application subscription for a command:
@bot.slash_command() async def cool_command(inter: disnake.ApplicationCommandInteraction): if not inter.entitlements: await inter.response.require_premium() return # skip remaining code ...
- Raises:
HTTPException – Sending the response has failed.
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
- poll
- 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
- asyncforward
- 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.Message
with 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
DMChannel
orGroupChannel
if it’s a private message.- Type:
Union[
TextChannel
,VoiceChannel
,StageChannel
,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
@everyone
or the@here
text is in the message itself. Rather this boolean indicates if either the@everyone
or the@here
text is in the message and it did end up mentioning.- Type:
- mentions¶
A list of
Member
that were mentioned. If the message is in a private message then the list will be ofUser
instead.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
Role
that 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 edit(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., suppress_embeds=..., flags=..., allowed_mentions=..., view=..., components=..., delete_after=None)[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
file
parameter 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, orNone
to clear it.embed (Optional[
Embed
]) – The new embed to replace the original with. This cannot be mixed with theembeds
parameter. Could beNone
to 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 theembed
parameter. To remove all embeds[]
should be passed.file (
File
) – The file to upload. This cannot be mixed with thefiles
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.files (List[
File
]) – A list of files to upload. This cannot be mixed with thefile
parameter. Files will be appended to the message, see theattachments
parameter to remove/replace existing files.attachments (Optional[List[
Attachment
]]) –A list of attachments to keep in the message. If
[]
orNone
is 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
None
to clear attachments.view (Optional[
View
]) – The updated view to update this message with. This cannot be mixed withcomponents
. IfNone
is 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
. IfNone
is passed then the components are removed.New in version 2.4.
suppress_embeds (
bool
) –Whether to suppress embeds for the message. This hides all the embeds from the UI if set to
True
. If set toFalse
, this brings the embeds back if they were suppressed.New in version 2.7.
flags (
MessageFlags
) –The new flags to set for this message. Overrides existing flags. Only
suppress_embeds
is supported.If parameter
suppress_embeds
is provided, that will override the setting ofMessageFlags.suppress_embeds
.New in version 2.9.
allowed_mentions (
AllowedMentions
) – Controls the mentions being processed in this message. Seeabc.Messageable.send()
for more information.delete_after (Optional[
float
]) –If provided, the number of seconds to wait in the background before deleting the message we just edited. If the deletion fails, then it is silently ignored.
Can be up to 15 minutes after the interaction was created (see also
Interaction.expires_at
/is_expired
).New in version 2.10.
- Raises:
HTTPException – Editing the message failed.
Forbidden – Edited a message that is not yours.
TypeError – You specified both
embed
andembeds
orfile
andfiles
ValueError – The length of
embeds
was 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.
- 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_history
permission to use this. If nobody else has reacted to the message using this emoji, theadd_reactions
permission is required.Changed in version 2.6: Raises
TypeError
instead 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.GuildChannel
that 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_messages
permission to use this.New in version 1.3.
Changed in version 2.6: Raises
TypeError
instead 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_messages
permission 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_threads
in 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
TypeError
instead 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 (Optional[
int
]) –Specifies the slowmode rate limit for users in this thread, in seconds. A value of
0
disables slowmode. The maximum value possible is21600
. If set toNone
or not provided, slowmode is inherited from the parent’sdefault_thread_slowmode_delay
.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
]
- await forward(channel)[source]¶
This function is a coroutine.
A shortcut method to
abc.Messageable.send()
to forward aMessage
.New in version 2.10.
- Parameters:
channel (Union[
TextChannel
,VoiceChannel
,StageChannel
,Thread
,DMChannel
,GroupChannel
,PartialMessageable
]) – The channel where the message should be forwarded to.- Raises:
HTTPException – Sending the message failed.
Forbidden – You do not have the proper permissions to send the message.
- Returns:
The message that was sent.
- Return type:
- 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_messages
permission to do this in a non-private channel context.This does not work with messages sent in a
VoiceChannel
orStageChannel
.- 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 or the channel not supporting pins.
- await publish()[source]¶
This function is a coroutine.
Publishes this message to your announcement channel.
You must have the
send_messages
permission to do this.If the message is not your own then the
manage_messages
permission 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.
member
parameter is not you) then themanage_messages
permission is needed.The
member
parameter must represent a member and meet theabc.Snowflake
abc.Changed in version 2.6: Raises
TypeError
instead 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_exists
keyword argument. Defaults toTrue
.Changed in version 2.6: Raises
TypeError
orValueError
instead ofInvalidArgument
.- Parameters:
fail_if_not_exists (
bool
) –Whether replying using the message reference should raise
HTTPException
if 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
embed
andembeds
, orfile
andfiles
, orview
andcomponents
.ValueError – The
files
orembeds
list 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.default
andMessageType.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.
None
if no thread has been started.New in version 2.4.
- Type:
Optional[
Thread
]
- to_reference(*, type=<MessageReferenceType.default: 0>, fail_if_not_exists=True)[source]¶
Creates a
MessageReference
from the current message.New in version 1.6.
- Parameters:
type (
MessageReferenceType
) –The type of the message reference. This is used to control whether to reply to or forward a message. Defaults to replying.
New in version 2.10.
fail_if_not_exists (
bool
) –Whether replying using the message reference should raise
HTTPException
if 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_messages
permission 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.
InteractionDataResolved¶
- class disnake.InteractionDataResolved[source]¶
Represents the resolved data related to an interaction.
New in version 2.1.
Changed in version 2.7: Renamed from
ApplicationCommandInteractionDataResolved
toInteractionDataResolved
.- members¶
A mapping of IDs to partial members (
deaf
andmute
attributes are missing).
- channels¶
A mapping of IDs to partial channels (only
id
,name
andpermissions
are included, threads also havethread_metadata
andparent_id
).- Type:
Dict[
int
, Union[abc.GuildChannel
,Thread
,abc.PrivateChannel
,PartialMessageable
]]
- attachments¶
A mapping of IDs to attachments.
New in version 2.4.
- Type:
Dict[
int
,Attachment
]
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.
- Type:
- options¶
A list of options from the API.
- Type:
- target¶
The user or message targetted by a user or message command
ApplicationCommandInteractionDataOption¶
MessageInteractionData¶
- class disnake.MessageInteractionData[source]¶
Represents the data of an interaction with a message component.
New in version 2.1.
- component_type¶
The type of the component.
- Type:
- values¶
The values the user has selected in a select menu. For non-string select menus, this contains IDs for use with
resolved
.- Type:
Optional[List[
str
]]
- resolved¶
All resolved objects related to this interaction.
New in version 2.7.
- Type:
ModalInteractionData¶
Enumerations¶
InteractionType¶
- class disnake.InteractionType[source]¶
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]¶
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¶
Responds 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()
New in version 2.4.
Responds to the interaction with a message containing an upgrade button. Only available for applications with monetization enabled.
See also
InteractionResponse.require_premium()
New in version 2.10.