Interactions
You can receive general interactions of all possible types with the client event interaction_received
.
This event passes a Interaction
object which you can defer, respond to or whatever you want
Example
# client stuff before
from discord_ui import Interaction
@client.listen("on_interaction_received")
async def on_interaction(interaction: Interaction):
await interaction.respond("houston we got an interaction")
Interaction
- class discord_ui.Interaction
- application_id: int
The ID of the bot application
- author: Union[discord.member.Member, discord.user.User]
The user who created the interaction
- property channel: Union[discord.abc.GuildChannel, discord.abc.PrivateChannel]
The channel where the interaction was created
- channel_id: int
The channel-id where the interaction was created
- property created_at
The interaction’s creation time in UTC
- data: dict
The passed data of the interaction
- async defer(hidden=False)
This will acknowledge the interaction. This will show the (Bot is thinking…) Dialog
Note
This function should be used if the bot needs more than 15 seconds to respond
- hidden:
bool
, optional Whether the loading thing should be only visible to the user; default False.
- hidden:
- property guild: discord.guild.Guild
The guild where the interaction was created
- guild_id: int
The guild-id where the interaction was created
- id: int
The id of the interaction
- message: discord_ui.receive.Message
The message in which the interaction was created
- async respond(content=None, *, tts=False, embed=None, embeds=None, file=None, files=None, nonce=None, allowed_mentions=None, mention_author=None, components=None, delete_after=None, listener=None, hidden=False, ninja_mode=False) Union[Message, EphemeralMessage]
Responds to the interaction
- content:
str
, optional The raw message content
- tts:
bool
Whether the message should be send with text-to-speech
- embed:
discord.Embed
Embed rich content
- embeds: List[
discord.Embed
] A list of embeds for the message
- file:
discord.File
The file which will be attached to the message
- files: List[
discord.File
] A list of files which will be attached to the message
- nonce:
int
The nonce to use for sending this message
- allowed_mentions:
discord.AllowedMentions
Controls the mentions being processed in this message
- mention_author:
bool
Whether the author should be mentioned
- components: List[
Button
|LinkButton
|SelectMenu
] A list of message components to be included
- delete_after:
float
After how many seconds the message should be deleted, only works for non-hiddend messages; default MISSING
- listener:
Listener
A component-listener for this message
- hidden:
bool
Whether the response should be visible only to the user
- ninja_mode:
bool
If true, the client will respond to the button interaction with almost nothing and returns nothing
Message
|EphemeralMessage
Returns the sent message
- content:
- async send(content=None, *, tts=None, embed=None, embeds=None, file=None, files=None, nonce=None, allowed_mentions=None, mention_author=None, components=None, delete_after=None, listener=None, hidden=False, force=False) Union[discord_ui.receive.Message, discord_ui.receive.EphemeralMessage]
Sends a message to the interaction using a webhook
- content:
str
, optional The raw message content
- tts:
bool
, optional Whether the message should be send with text-to-speech
- embed:
discord.Embed
, optional Embed rich content
- embeds: List[
discord.Embed
], optional A list of embeds for the message
- file:
discord.File
, optional The file which will be attached to the message
- files: List[
discord.File
], optional A list of files which will be attached to the message
- nonce:
int
, optional The nonce to use for sending this message
- allowed_mentions:
discord.AllowedMentions
, optional Controls the mentions being processed in this message
- mention_author:
bool
, optional Whether the author should be mentioned
- components: List[
Button
|LinkButton
|SelectMenu
] A list of message components to be included
- delete_after:
float
, optional After how many seconds the message should be deleted, only works for non-hiddend messages; default MISSING
- listener:
Listener
, optional A component-listener for this message
- hidden:
bool
, optional Whether the response should be visible only to the user
- ninja_mode:
bool
, optional If true, the client will respond to the button interaction with almost nothing and returns nothing
- force:
bool
, optional Whether sending the follow-up message should be forced. If
False
, then a follow-up message will only be send if.responded
is True; default False
Message
|EphemeralMessage
Returns the sent message
- content:
- token: str
The token for responding to the interaction
- type: int
The type of the interaction. See
InteractionType
for more information
Application commands
- class discord_ui.SlashInteraction
An interaction created by a
SlashCommand
- args: Dict[str, Union[str, int, bool, discord.member.Member, discord.channel.TextChannel, discord.role.Role, float]]
The options that were received
- author: Union[discord.member.Member, discord.user.User]
The user who used the command
- command: discord_ui.slash.types.SlashCommand
The original command instance that was used. If you change things here, the changes will be applied globally
- permissions: discord_ui.slash.types.SlashPermission
The permissions for this guild
- class discord_ui.ContextInteraction
An interaction created by a
MessageCommand
or aUserCommand
- command: discord_ui.slash.types.ContextCommand
The original command instance that was used
- permissions: discord_ui.slash.types.SlashPermission
The permissions for this guild
- target: Union[discord_ui.receive.Message, discord.member.Member, discord.user.User]
The target object on which the interaction was used
- class discord_ui.AutocompleteInteraction
Autocomplete interaction
- command: Union[discord_ui.receive.SlashInteraction, discord_ui.receive.ContextInteraction]
The slash command for which the choices should be generated
- async defer(*args, **kwargs)
Cannot defer this type of interaction
- focused_option: dict
The option for which the choices should be generated
- async respond(*args, **kwargs)
Response will be made automatically with the choices that are returned
- selected_options: Dict[str, Any]
All the options that were already selected. Format:
{"option name": value}
- async send(*args, **kwargs)
Cannot send followup message to this type of interaction
- value_query: Union[str, int]
The current input of the focused option
Components
- class discord_ui.ButtonInteraction
An interaction that was created by a
Button
- author: discord.member.Member
The user who pressed the button
- component: discord_ui.components.Button
The component that created the interaction
- class discord_ui.SelectInteraction
An interaction that was created by a
SelectMenu
- author: discord.member.Member
The user who selected the value
- selected_options: List[discord_ui.components.SelectOption]
The list of the selected options
- selected_values: List[str]
The list of raw values which were selected