Interaction Implementation#

Interaction implementations extending disnake interactions.

Classes#

class components.interaction.WrappedInteraction(wrapped)[source]#

Bases: Interaction

Interaction implementation that wraps disnake.Interaction.

This wrapped interaction class natively supports disnake-ext-components’ specialised components classes and – unlike vanilla disnake interactions – can send them without manually having to convert them to native disnake components first.

Attribute access is simply proxied to the wrapped interaction object by means of a custom __getattr__() implementation.

await edit_original_message(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., view=..., components=..., suppress_embeds=..., allowed_mentions=None)[source]#

Edit 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 with Embed.set_image() or Embed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by setting file/ 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, or :obj:None to clear it.

  • embed (Optional[Embed]) – The new embed to replace the original with. This cannot be mixed with the embeds parameter. Could be None 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 the embed 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, see the attachments parameter to remove/replace existing files.

  • files (List[File]) – A list of files to upload. This cannot be mixed with the file parameter. Files will be appended to the message, see the attachments parameter to remove/replace existing files.

  • attachments (Optional[List[Attachment]]) –

    A list of attachments to keep in the message. If [] or None 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 with components. If None is passed then the view is removed.

  • components (Optional[RichButton | Button[Any] | RichSelect | StringSelect[Any] | ChannelSelect[Any] | RoleSelect[Any] | UserSelect[Any] | MentionableSelect[Any] | Sequence[RichButton | Button[Any] | RichSelect | StringSelect[Any] | ChannelSelect[Any] | RoleSelect[Any] | UserSelect[Any] | MentionableSelect[Any] | Sequence[Components]]]) –

    A list of components to update this message with. This cannot be mixed with view. If None is passed then the components are removed.

    New in version 2.4.

  • allowed_mentions (Optional[AllowedMentions]) – Controls the mentions being processed in this message. See abc.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 to False, this brings the embeds back if they were suppressed.

    New in version 2.7.

  • flags

    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 of MessageFlags.suppress_embeds.

    New in version 2.9.

Raises:
Returns:

The newly edited message.

Return type:

InteractionMessage

await edit_original_response(content=..., *, embed=..., embeds=..., file=..., files=..., attachments=..., view=..., components=..., suppress_embeds=..., allowed_mentions=None)[source]#

Edit 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 with Embed.set_image() or Embed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by setting file/ 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, or :obj:None to clear it.

  • embed (Optional[Embed]) – The new embed to replace the original with. This cannot be mixed with the embeds parameter. Could be None 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 the embed 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, see the attachments parameter to remove/replace existing files.

  • files (List[File]) – A list of files to upload. This cannot be mixed with the file parameter. Files will be appended to the message, see the attachments parameter to remove/replace existing files.

  • attachments (Optional[List[Attachment]]) –

    A list of attachments to keep in the message. If [] or None 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 with components. If None is passed then the view is removed.

  • components (Optional[RichButton | Button[Any] | RichSelect | StringSelect[Any] | ChannelSelect[Any] | RoleSelect[Any] | UserSelect[Any] | MentionableSelect[Any] | Sequence[RichButton | Button[Any] | RichSelect | StringSelect[Any] | ChannelSelect[Any] | RoleSelect[Any] | UserSelect[Any] | MentionableSelect[Any] | Sequence[Components]]]) –

    A list of components to update this message with. This cannot be mixed with view. If None is passed then the components are removed.

    New in version 2.4.

  • allowed_mentions (Optional[AllowedMentions]) – Controls the mentions being processed in this message. See abc.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 to False, this brings the embeds back if they were suppressed.

    New in version 2.7.

  • flags

    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 of MessageFlags.suppress_embeds.

    New in version 2.9.

Raises:
Returns:

The newly edited message.

Return type:

InteractionMessage

await send(content=None, *, embed=..., embeds=..., file=..., files=..., allowed_mentions=..., view=..., components=..., tts=False, ephemeral=False, suppress_embeds=False, delete_after=...)[source]#

|coro|

Sends a message using either response.send_message or followup.send.

If the interaction hasn’t been responded to yet, this method will call response.send_message. Otherwise, it will call followup.send.

Note

This method does not return a Message object. If you need a message object, use original_response() to fetch it, or use followup.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 the embeds parameter.

  • embeds (List[Embed]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with the embed parameter.

  • file (File) – The file to upload. This cannot be mixed with the files parameter.

  • files (List[File]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with the file parameter.

  • allowed_mentions (AllowedMentions) – Controls the mentions being processed in this message. If this is passed, then the object is merged with Client.allowed_mentions. The merging behaviour only overrides attributes that have been explicitly passed to the object, otherwise it uses the attributes set in Client.allowed_mentions. If no object is passed at all then the defaults given by Client.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 with components.

  • components (|components_type|) –

    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 and suppress_notifications are supported.

    If parameters suppress_embeds or ephemeral are provided, they will override the corresponding setting of this flags 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.

Raises:
  • HTTPException – Sending the message failed.

  • TypeError – You specified both embed and embeds.

  • ValueError – The length of embeds was invalid.

followup#

Returns the follow up webhook for follow up interactions.

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.

class components.interaction.WrappedInteractionResponse(wrapped)[source]#

Bases: InteractionResponse

Interaction response implementation that wraps disnake.InteractionResponse.

This wrapped interaction response class natively supports disnake-ext-components’ specialised components classes and – unlike vanilla disnake interactions – can send them without manually having to convert them to native disnake components first.

Attribute access is simply proxied to the wrapped interaction response object by means of a custom __getattr__() implementation.

await edit_message(content=None, *, embed=..., embeds=..., file=..., files=..., attachments=..., allowed_mentions=..., view=..., components=...)[source]#

|coro|

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 with Embed.set_image() or Embed.set_thumbnail()), those images will be removed if the message’s attachments are edited in any way (i.e. by setting file/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 the embeds parameter. Could be None 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 the embed 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 [] or None 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 with components. If None is passed then the view is removed.

  • components (Optional[|components_type|]) –

    A list of components to update this message with. This cannot be mixed with view. If None is passed then the components are removed.

    New in version 2.4.

Raises:
  • HTTPException – Editing the message failed.

  • TypeError – You specified both embed and embeds.

  • 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=False, suppress_embeds=False, delete_after=...)[source]#

|coro|

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 the embeds parameter.

  • embeds (List[Embed]) – A list of embeds to send with the content. Must be a maximum of 10. This cannot be mixed with the embed parameter.

  • file (File) – The file to upload. This cannot be mixed with the files parameter.

  • files (List[File]) – A list of files to upload. Must be a maximum of 10. This cannot be mixed with the file 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 with components.

  • components (|components_type|) –

    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 and suppress_notifications are supported.

    If parameters suppress_embeds or ephemeral are provided, they will override the corresponding setting of this flags parameter.

    New in version 2.9.

Raises:
  • HTTPException – Sending the message failed.

  • TypeError – You specified both embed and embeds.

  • ValueError – The length of embeds was invalid.

  • InteractionResponded – This interaction has already been responded to before.

class components.interaction.MessageInteraction(wrapped)[source]#

Bases: WrappedInteraction, MessageInteraction

Message interaction implementation that wraps disnake.MessageInteraction.

This wrapped message interaction class natively supports disnake-ext-components’ specialised components classes and – unlike vanilla disnake interactions – can send them without manually having to convert them to native disnake components first.

Attribute access is simply proxied to the wrapped message interaction object by means of a custom __getattr__() implementation.

Functions#

components.interaction.wrap_interaction(interaction)[source]#

Wrap a disnake interaction type for disnake-ext-components compatibility.

Interactions wrapped in this way can send disnake-ext-components’ specialised components directly, without having to first convert them to native disnake components.

Parameters:

interaction (Interaction) – The interaction to wrap.

Returns:

The wrapped interaction. Note that this can be any subclass of WrappedInteraction:

Return type:

WrappedInteraction