Event Context#

class interactions.client.context._Context(kwargs_dict=None, /, **other_kwargs)#

The base class of “context” for dispatched event data from the gateway. The premise of having this class is so that the user-facing API is able to allow developers to easily access information presented from any event in a “contextualized” sense.

Variables:
  • message? (Optional[Message]) – The message data model.

  • author (Member) – The member data model.

  • user (User) – The user data model.

  • channel (Optional[Channel]) – The channel data model.

  • guild (Optional[Guild]) – The guild data model.

Parameters:

kwargs_dict (dict) –

async get_channel()#

This gets the channel the context was invoked in.

Returns:

The channel as object

Return type:

Channel

async get_guild()#

This gets the guild the context was invoked in.

Returns:

The guild as object

Return type:

Guild

async send(content=<interactions.MISSING>, *, tts=<interactions.MISSING>, attachments=<interactions.MISSING>, embeds=<interactions.MISSING>, allowed_mentions=<interactions.MISSING>, components=<interactions.MISSING>, ephemeral=False, suppress_embeds=False)#

This allows the invocation state described in the “context” to send an interaction response.

Parameters:
Returns:

The sent message as an object.

Return type:

Message

async edit(content=<interactions.MISSING>, *, tts=<interactions.MISSING>, attachments=<interactions.MISSING>, embeds=<interactions.MISSING>, allowed_mentions=<interactions.MISSING>, message_reference=<interactions.MISSING>, components=<interactions.MISSING>)#

This allows the invocation state described in the “context” to send an interaction response. This inherits the arguments of the Context .send() method.

Returns:

The edited message as an object.

Return type:

Message

Parameters:
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

async has_permissions(*permissions, operator='and')#

Returns whether the author of the interaction has the permissions in the given context.

Parameters:
  • *permissions

    The list of permissions

  • operator (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

_extras: dict#

A dict containing values that were not serialized from Discord.

update(kwargs_dict=None, /, **other_kwargs)#

Update an object with new attributes. All data will be converted, and any extra attributes will be put in _extras

Parameters:

kwargs_dict (dict) – The dictionary to update from

class interactions.client.context.CommandContext(kwargs_dict=None, /, **other_kwargs)#

A derivation of interactions.context.Context designed specifically for application command data.

Warning

The guild attribute of the base context is not accessible for any interaction-related events since the current Discord API schema does not return this as a value, but instead guild_id. You will need to manually fetch for this data for the time being.

You can fetch with client.get_guild(guild_id) which will return a JSON dictionary, which you can then use interactions.Guild(**data) for an object or continue with a dictionary for your own purposes.

Variables:
  • _client – the HTTP client

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

  • responded (bool) – Whether an original response was made or not.

  • deferred (bool) – Whether the response was deferred or not.

  • locale? (str) – The selected language of the user invoking the interaction.

  • guild_locale? (str) – 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) – The client instance that the command belongs to.

  • command (Command) – The command object that is being invoked.

  • extension (Extension) – The extension the command belongs to.

Parameters:

kwargs_dict (dict) –

async edit(content=<interactions.MISSING>, **kwargs)#

This allows the invocation state described in the “context” to send an interaction response. This inherits the arguments of the Context .send() method.

Returns:

The edited message as an object.

Return type:

Message

Parameters:

content (Optional[str]) –

async defer(ephemeral=False)#

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.

  • ephemeral (Optional[bool]) –

Return type:

None

async send(content=<interactions.MISSING>, **kwargs)#

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

  • 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 (bool) – Whether embeds are not shown in the message.

  • content (Optional[str]) –

Returns:

The sent message as an object.

Return type:

Message

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.

Return type:

None

async populate(choices)#

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]

_extras: dict#

A dict containing values that were not serialized from Discord.

async get_channel()#

This gets the channel the context was invoked in.

Returns:

The channel as object

Return type:

Channel

async get_guild()#

This gets the guild the context was invoked in.

Returns:

The guild as object

Return type:

Guild

async has_permissions(*permissions, operator='and')#

Returns whether the author of the interaction has the permissions in the given context.

Parameters:
  • *permissions

    The list of permissions

  • operator (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

update(kwargs_dict=None, /, **other_kwargs)#

Update an object with new attributes. All data will be converted, and any extra attributes will be put in _extras

Parameters:

kwargs_dict (dict) – The dictionary to update from

class interactions.client.context.ComponentContext(kwargs_dict=None, /, **other_kwargs)#

A derivation of interactions.context.CommandContext designed specifically for component data.

Parameters:

kwargs_dict (dict) –

async edit(content=<interactions.MISSING>, **kwargs)#

This allows the invocation state described in the “context” to send an interaction response. This inherits the arguments of the Context .send() method.

Returns:

The edited message as an object.

Return type:

Message

Parameters:

content (Optional[str]) –

async send(content=<interactions.MISSING>, **kwargs)#

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

  • 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 (bool) – Whether embeds are not shown in the message.

  • content (Optional[str]) –

Returns:

The sent message as an object.

Return type:

Message

async defer(ephemeral=False, edit_origin=False)#

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

  • ephemeral (Optional[bool]) –

  • edit_origin (Optional[bool]) –

Return type:

None

async disable_all_components(respond_to_interaction=True, **other_kwargs)#

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 interactions.client.context._Context:edit()

  • respond_to_interaction (Optional[bool]) –

  • other_kwargs (Optional[dict]) –

Returns:

The modified Message

Return type:

Message

property label: Optional[str]#

The label of the interacted button. :rtype: Optional[str]

_extras: dict#

A dict containing values that were not serialized from Discord.

async get_channel()#

This gets the channel the context was invoked in.

Returns:

The channel as object

Return type:

Channel

async get_guild()#

This gets the guild the context was invoked in.

Returns:

The guild as object

Return type:

Guild

async has_permissions(*permissions, operator='and')#

Returns whether the author of the interaction has the permissions in the given context.

Parameters:
  • *permissions

    The list of permissions

  • operator (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

update(kwargs_dict=None, /, **other_kwargs)#

Update an object with new attributes. All data will be converted, and any extra attributes will be put in _extras

Parameters:

kwargs_dict (dict) – The dictionary to update from