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 (str) – 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:

Message

async defer(ephemeral=False)[source]#

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.

Parameters:

ephemeral (Optional[bool]) – Whether the deferred state is hidden or not.

Returns:

The deferred message

Return type:

Message

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:

Message

async delete()[source]#

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 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.

Parameters:

choices (Union[Choice, List[Choice]]) – The choices you wish to present.

Returns:

The list of choices you’ve given.

Return type:

List[Choice]

property author: Optional[Member]#

Returns the author/member that invoked the interaction.

property channel: Optional[Channel]#

New in version 4.1.0.

Changed in version 4.4.0: Channel now returns None instead of MISSING if it is not found to avoid confusion

Returns the current channel, if cached.

property created_at: datetime#

New in version 4.4.0.

Returns when the interaction was created.

property deferred_ephemeral: bool#

New in version 4.4.0.

Returns whether the current interaction was deferred ephemerally.

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:

Channel

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:

Guild

property guild: Optional[Guild]#

New in version 4.1.0.

Changed in version 4.4.0: Guild now returns None instead of MISSING if it is not found to avoid confusion

Returns 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 to and.

Returns:

Whether the author has the permissions

Return type:

bool

async popup(modal)#

This “pops up” a modal to present information back to the user.

Parameters:

modal (Modal) – The components you wish to show.

Return type:

dict

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 (str) – 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:

Message

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:

Message

async defer(ephemeral=False, edit_origin=False)[source]#

Changed in version 4.4.0: Now returns the created message object

This “defers” a component response, allowing up to a 15-minute delay between invocation and responding.

Parameters:
  • ephemeral (Optional[bool]) – Whether the deferred state is hidden or not.

  • edit_origin (Optional[bool]) – Whether you want to edit the original message or send a followup message

Returns:

The deferred message

Return type:

Message

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:

Message

property custom_id: Optional[str]#

The custom ID of the interacted component.

Return type:

Optional[str]

property label: Optional[str]#

The label of the interacted button.

Return type:

Optional[str]

property author: Optional[Member]#

Returns the author/member that invoked the interaction.

property channel: Optional[Channel]#

New in version 4.1.0.

Changed in version 4.4.0: Channel now returns None instead of MISSING if it is not found to avoid confusion

Returns the current channel, if cached.

property created_at: datetime#

New in version 4.4.0.

Returns when the interaction was created.

property deferred_ephemeral: bool#

New in version 4.4.0.

Returns whether the current interaction was deferred ephemerally.

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:

Channel

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:

Guild

property guild: Optional[Guild]#

New in version 4.1.0.

Changed in version 4.4.0: Guild now returns None instead of MISSING if it is not found to avoid confusion

Returns 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 to and.

Returns:

Whether the author has the permissions

Return type:

bool

async popup(modal)#

This “pops up” a modal to present information back to the user.

Parameters:

modal (Modal) – The components you wish to show.

Return type:

dict