Interaction

class InteractionCallbackType

This is located in discord.enums but i place it here.

InteractionCallbackType to react to an Interaction

NAME

VALUE

DESCRIPTION

USAGE

EXAMPLE

pong

1

ACK a Ping

ACK a Ping to Discord

~

msg_with_source

4

respond to an interaction with a message

Interaction.respond

Click for example

Example for msg_with_source
deferred_msg_with_source

5

ACK an interaction and edit a response later, the user sees a loading state

Possible response_type for defer

Click for example

Example for deferred_msg_with_source
deferred_update_msg

6

for components, ACK an interaction and edit the original message later; the user does not see a loading state

Possible response_type for defer

Click for example

Example for deferred_update_msg
update_msg

7

for components, edit the message the component was attached to

Interaction.edit

Click for example

Example for update_msg
class Interaction

Warning

Do not initiate this Class manually

Represents an interaction created in discord like click an Button or select an option of SelectMenu

Note

For general information’s about Interactions visit the Discord-API-Documentation of the discord-api.

author

A Member that invoked the interaction. If channel is a private channel or the user has left the guild, then it is a User instead.

message

The message the component was attached to. This will be EphemeralMessage if the component_type is not None or the message the component is attached to is ephemeral.

Note

In this version, this parameter should always be an object of type discord.Message (or EphemeralMessage if the message is ephemeral) because it only gets initiated when the interaction_type is higher than 2.

channel

The Channel the interaction was created in this is aiter an object of discord.TextChannel if it’s inside a guild else it’s an object of type discord.DMChannel.

guild

The guild associated with the interaction; aiter an object of type discord.Guild, except the interaction was inside an dm-channel then this would be equal to None

component

The component that invoked this interaction: Aiter an object of type Button or SelectMenu if the message is not ephemeral else type ButtonClick or SelectionSelect

Note

If this is passed in an [on_][raw_]button_click or [on_][raw_]selection_select Event there would be a second parameter that includes this attribute.

created_at

Returns the Interaction’s creation time in UTC.

Type

datetime.datetime

defer(response_type: Literal[5, 6] = InteractionCallbackType.deferred_update_msg, hidden: bool = False)

|coro|

‘Defers’ the response.

If response_type is InteractionCallbackType.deferred_msg_with_source it shows a loading state to the user.

Parameters

Important

If you doesn’t respond with an message using respond() or edit the original message using edit() within less than 3 seconds, discord will indicates that the interaction failed and the interaction-token will be invalidated. To provide this us this method

Note

A Token will be Valid for 15 Minutes so you could edit the original message with edit(), respond() or doing anything other with this interaction for 15 minutes. after that time you have to edit the original message with the Methode edit of the message and sending new messages with the send Methode of channel (you could not do this hidden as it isn’t an interaction-response anymore)

edit(**fields)

|coro|

Edit the Message the component is attached to, if the interaction is not deferred it will defer automatic.

Note

If you have not yet deferred or deferred with type InteractionCallbackType.deferred_update_msg, edit the message to which the component is attached, otherwise edit the callback message.

Parameters

**fields – The fields of the original message to replace. You could pass the same Parameters as using discord.Message.edit()

respond(**kwargs)

|coro|

You could pass the same Parameters as using discord.Messageable.send() but there are one more optional: Responds to an interaction by sending a message that can be made visible only to the person who invoked the interaction by setting the hidden to True.

Parameters

hidden

Optional[bool] If set to True, the message will be only visible(e.g. ephemeral) for the author of the Interaction and will disappears if the author click on delete this message, the message go out of his view or he reloads the client.

Note

If you send an hidden (ephemeral)-respond, discord don’t returns any data like an message you could edit, but you could receive Interactions when the Author interact with an component in the message.

Returns

Union[discord.Message, EphemeralMessage]


class ButtonClick

The object that contains a Interaction.component if it is of type 2 and the message is ephemeral.

custom_id

Union[str, int]

The custom_id of the Button. If the custom_id is a number it is returned as an integer, otherwise a string.


class SelectionSelect

The object containing a Interaction.component contains, if it is of type 3 and the message is ephemeral.

custom_id

Union[str, int]

The custom_id of the SelectMenu. If the custom_id is a number it is returned as an integer, otherwise a string.

values

List[Union[str, int]] A list of the options that have been selected. If the value is a number it is returned as an integer, otherwise a string


class EphemeralMessage

Since Discord doesn’t return anything when we send a ephemeral message, this class has no attributes and you can’t do anything with it.

Indices and tables