Event Context#
- class interactions.client.context.CommandContext(kwargs_dict=None, /, **other_kwargs)[source]#
A derivation of context designed specifically for application command data.
- Variables:
id (Snowflake) – The ID of the interaction.
application_id (Snowflake) – The application ID of the interaction.
type (InteractionType) – The type of interaction.
data (InteractionData) – The application command data.
target (Optional[Union[Message, Member, User]]) – The target selected if this interaction is invoked as a context menu.
token (str) – The token of the interaction response.
guild_id (Snowflake) – The ID of the current guild.
channel_id (Snowflake) – The ID of the current channel.
user (User) – The user data model.
responded (bool) – Whether an original response was made or not.
deferred (bool) – Whether the response was deferred or not.
locale (Optional[Locale]) – The selected language of the user invoking the interaction.
guild_locale (Optional[Locale]) – The guild’s preferred language, if invoked in a guild.
app_permissions (Permissions) – Bitwise set of permissions the bot has within the channel the interaction was sent from.
client (Client) –
New in version 4.3.0.
The client instance that the command belongs to.
command (Command) –
New in version 4.3.0.
The command object that is being invoked.
extension (Extension) –
New in version 4.3.0.
The extension the command belongs to.
- async edit(content=<interactions.MISSING>, **kwargs)[source]#
This allows the invocation state described in the “context” to send an interaction response.
- Parameters:
content (Optional[str]) – The contents of the message as a string or string-converted value.
tts (Optional[bool]) – Whether the message utilizes the text-to-speech Discord programme or not.
attachments (Optional[List[Attachment]]) – The attachments to attach to the message. Needs to be uploaded to the CDN first
files (Optional[Union[File, List[File]]]) –
New in version 4.4.0.
The files to attach to the message.
embeds (Optional[Union[Embed, List[Embed]]]) – An embed, or list of embeds for the message.
allowed_mentions (Optional[Union[AllowedMentions, dict]]) – The allowed mentions for the message.
message_reference (Optional[MessageReference]) – Include to make your message a reply.
components (Optional[Union[ActionRow, Button, SelectMenu, List[Union[ActionRow, Button, SelectMenu]]]]) – A component, or list of components for the message.
- Returns:
The edited message.
- Return type:
- async send(content=<interactions.MISSING>, **kwargs)[source]#
This allows the invocation state described in the “context” to send an interaction response.
- Parameters:
content (Optional[str]) – The contents of the message as a string or string-converted value.
tts (Optional[bool]) – Whether the message utilizes the text-to-speech Discord programme or not.
attachments (Optional[List[Attachment]]) – The attachments to attach to the message. Needs to be uploaded to the CDN first
files (Optional[Union[File, List[File]]]) –
New in version 4.4.0.
The files to attach to the message.
embeds (Optional[Union[Embed, List[Embed]]]) – An embed, or list of embeds for the message.
allowed_mentions (Optional[Union[AllowedMentions, dict]]) – The allowed mentions for the message.
components (Optional[Union[ActionRow, Button, SelectMenu, List[Union[ActionRow, Button, SelectMenu]]]]) – A component, or list of components for the message.
ephemeral (Optional[bool]) – Whether the response is hidden or not.
suppress_embeds (Optional[bool]) – Whether embeds are not shown in the message.
- Returns:
The sent message.
- Return type:
- async populate(choices)[source]#
This “populates” the list of choices that the client-end user will be able to select from in the autocomplete field.
Warning
Only a maximum of
25
choices may be presented within an autocomplete option.
- property channel: Channel | None#
New in version 4.1.0.
Changed in version 4.4.0: Channel now returns
None
instead ofMISSING
if it is not found to avoid confusionReturns the current channel, if cached.
- async defer(ephemeral=False, edit_origin=False)#
Changed in version 4.4.0: Now returns the created message object
This “defers” an interaction response, allowing up to a 15-minute delay between invocation and responding.
- property deferred_ephemeral: bool#
New in version 4.4.0.
Returns whether the current interaction was deferred ephemerally.
- async delete()#
This deletes the interaction response of a message sent by the contextually derived information from this class.
Note
Doing this will proceed in the context message no longer being present.
- async get_channel()#
New in version 4.1.0.
This gets the channel the context was invoked in. If the channel is not cached, an HTTP request is made.
- Returns:
The channel as object
- Return type:
- async get_guild()#
New in version 4.1.0.
This gets the guild the context was invoked in. If the guild is not cached, an HTTP request is made.
- Returns:
The guild as object
- Return type:
- property guild: Guild | None#
New in version 4.1.0.
Changed in version 4.4.0: Guild now returns
None
instead ofMISSING
if it is not found to avoid confusionReturns the current guild, if cached.
- async has_permissions(*permissions, operator='and')#
New in version 4.3.2.
Returns whether the author of the interaction has the permissions in the given context.
- Parameters:
*permissions (Union[int, Permissions]) – The list of permissions
operator (Optional[str]) – The operator to use to calculate permissions. Possible values:
and
,or
. Defaults toand
.
- Returns:
Whether the author has the permissions
- Return type:
- class interactions.client.context.ComponentContext(kwargs_dict=None, /, **other_kwargs)[source]#
A derivation of context designed specifically for component data.
- Variables:
id (Snowflake) – The ID of the interaction.
application_id (Snowflake) – The application ID of the interaction.
type (InteractionType) – The type of interaction.
data (InteractionData) – The application command data.
token (str) – The token of the interaction response.
guild_id (Snowflake) – The ID of the current guild.
channel_id (Snowflake) – The ID of the current channel.
message (Optional[Message]) – The message data model.
user (User) – The user data model.
responded (bool) – Whether an original response was made or not.
deferred (bool) – Whether the response was deferred or not.
locale (Optional[Locale]) – The selected language of the user invoking the interaction.
guild_locale (Optional[Locale]) – The guild’s preferred language, if invoked in a guild.
app_permissions (Permissions) – Bitwise set of permissions the bot has within the channel the interaction was sent from.
- async edit(content=<interactions.MISSING>, **kwargs)[source]#
This allows the invocation state described in the “context” to send an interaction response.
- Parameters:
content (Optional[str]) – The contents of the message as a string or string-converted value.
tts (Optional[bool]) – Whether the message utilizes the text-to-speech Discord programme or not.
attachments (Optional[List[Attachment]]) – The attachments to attach to the message. Needs to be uploaded to the CDN first
files (Optional[Union[File, List[File]]]) –
New in version 4.4.0.
The files to attach to the message.
embeds (Optional[Union[Embed, List[Embed]]]) – An embed, or list of embeds for the message.
allowed_mentions (Optional[Union[AllowedMentions, dict]]) – The allowed mentions for the message.
message_reference (Optional[MessageReference]) – Include to make your message a reply.
components (Optional[Union[ActionRow, Button, SelectMenu, List[Union[ActionRow, Button, SelectMenu]]]]) – A component, or list of components for the message.
- Returns:
The edited message.
- Return type:
- async send(content=<interactions.MISSING>, **kwargs)[source]#
This allows the invocation state described in the “context” to send an interaction response.
- Parameters:
content (Optional[str]) – The contents of the message as a string or string-converted value.
tts (Optional[bool]) – Whether the message utilizes the text-to-speech Discord programme or not.
attachments (Optional[List[Attachment]]) – The attachments to attach to the message. Needs to be uploaded to the CDN first
files (Optional[Union[File, List[File]]]) –
New in version 4.4.0.
The files to attach to the message.
embeds (Optional[Union[Embed, List[Embed]]]) – An embed, or list of embeds for the message.
allowed_mentions (Optional[Union[AllowedMentions, dict]]) – The allowed mentions for the message.
components (Optional[Union[ActionRow, Button, SelectMenu, List[Union[ActionRow, Button, SelectMenu]]]]) – A component, or list of components for the message.
ephemeral (Optional[bool]) – Whether the response is hidden or not.
suppress_embeds (Optional[bool]) – Whether embeds are not shown in the message.
- Returns:
The sent message.
- Return type:
- async disable_all_components(respond_to_interaction=True, **other_kwargs)[source]#
New in version 4.3.2.
Disables all components of the message.
- Parameters:
respond_to_interaction (Optional[bool]) – Whether the components should be disabled in an interaction response, default True
**other_kwargs (Optional[dict]) – Additional keyword-arguments to pass to the edit method. This only works when this method is used as interaction response and takes the same arguments as
ComponentContext.edit()
- Returns:
The modified Message
- Return type:
- property custom_id: str | None#
The custom ID of the interacted component.
- Return type:
Optional[str]
- property component: Button | SelectMenu | None#
New in version 4.4.0.
The component that you interacted.
- Return type:
Optional[Union[Button, SelectMenu]]
- property channel: Channel | None#
New in version 4.1.0.
Changed in version 4.4.0: Channel now returns
None
instead ofMISSING
if it is not found to avoid confusionReturns the current channel, if cached.
- async defer(ephemeral=False, edit_origin=False)#
Changed in version 4.4.0: Now returns the created message object
This “defers” an interaction response, allowing up to a 15-minute delay between invocation and responding.
- property deferred_ephemeral: bool#
New in version 4.4.0.
Returns whether the current interaction was deferred ephemerally.
- async delete()#
This deletes the interaction response of a message sent by the contextually derived information from this class.
Note
Doing this will proceed in the context message no longer being present.
- async get_channel()#
New in version 4.1.0.
This gets the channel the context was invoked in. If the channel is not cached, an HTTP request is made.
- Returns:
The channel as object
- Return type:
- async get_guild()#
New in version 4.1.0.
This gets the guild the context was invoked in. If the guild is not cached, an HTTP request is made.
- Returns:
The guild as object
- Return type:
- property guild: Guild | None#
New in version 4.1.0.
Changed in version 4.4.0: Guild now returns
None
instead ofMISSING
if it is not found to avoid confusionReturns the current guild, if cached.
- async has_permissions(*permissions, operator='and')#
New in version 4.3.2.
Returns whether the author of the interaction has the permissions in the given context.
- Parameters:
*permissions (Union[int, Permissions]) – The list of permissions
operator (Optional[str]) – The operator to use to calculate permissions. Possible values:
and
,or
. Defaults toand
.
- Returns:
Whether the author has the permissions
- Return type: