Skip to content

Interaction

Interaction

Bases: Generic[ClientT]

Represents a Discord interaction.

An interaction happens when a user does an action that needs to be notified. Current examples are slash commands and components.

Attributes:

Name Type Description
id int

The interaction's ID.

type InteractionType

The interaction type.

guild_id Optional[int]

The guild ID the interaction was sent from.

channel Optional[Any]

The channel the interaction was sent from.

application_id int

The application ID that the interaction was for.

user Union[User, Member]

The user or member that sent the interaction.

message Optional[Message]

The message that sent this interaction. This is only available for :attr:InteractionType.component interactions.

token str

The token to continue the interaction. These are valid for 15 minutes.

data dict

The raw interaction data.

locale Locale

The locale of the user invoking the interaction.

guild_locale Optional[Locale]

The preferred locale of the guild the interaction was sent from, if any.

Source code in dismake/models/interaction.py
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
class Interaction(Generic[ClientT]):
    """Represents a Discord interaction.

    An interaction happens when a user does an action that needs to
    be notified. Current examples are slash commands and components.

    Attributes
    -----------
    id: int
        The interaction's ID.
    type: InteractionType
        The interaction type.
    guild_id: Optional[int]
        The guild ID the interaction was sent from.
    channel: Optional[Any]
        The channel the interaction was sent from.
    application_id: int
        The application ID that the interaction was for.
    user: Union[User, Member]
        The user or member that sent the interaction.
    message: Optional[Message]
        The message that sent this interaction.
        This is only available for :attr:`InteractionType.component` interactions.
    token: str
        The token to continue the interaction. These are valid
        for 15 minutes.
    data: dict
        The raw interaction data.
    locale: Locale
        The locale of the user invoking the interaction.
    guild_locale: Optional[Locale]
        The preferred locale of the guild the interaction was sent from, if any.
    """

    __slots__: Tuple[str, ...] = (
        "_client",
        "data",
        "id",
        "type",
        "application_id",
        "guild_id",
        "channel",
        "channel_id",
        "token",
        "version",
        "app_permissions",
        "locale",
        "guild_locale",
        "message",
        "user",
        "_responded",
    )

    def __init__(self, client: ClientT, data: InteractionData) -> None:
        self._client = client
        self.data = data
        self.id: int = int(data["id"])
        self.type: InteractionType = InteractionType(int(data["type"]))
        self.application_id: Snowflake = data["application_id"]
        self.guild_id: Optional[int] = get_as_snowflake(data, "guild_id")
        self.channel: Optional[Any] = get_as_snowflake(data, "channel")
        self.channel_id: Optional[int] = get_as_snowflake(data, "channel_id")
        self.token: str = data["token"]
        self.version: int = data["version"]
        self.app_permissions: Optional[str] = data.get("app_permissions")
        self.locale: Optional[str] = data.get("locale")
        self.guild_locale: Optional[str] = data.get("guild_locale")

        self.message: Optional[Message] = (
            Message(client=client, data=data["message"]) if "message" in data else None
        )

        self.user: Optional[Union[User, Member]] = (
            Member(client=client, guild_id=self.guild_id, data=data["member"])
            if self.guild_id is not None and "member" in data
            else User(client=client, data=data["user"])
            if "user" in data
            else None
        )

        self._responded: bool = False

    @property
    def is_ping(self) -> bool:
        """Indicates whether this interaction is a Ping Interaction."""
        return self.type == InteractionType.PING

    @property
    def is_application_command(self) -> bool:
        """Indicates whether this interaction is an Application Command Interaction."""
        return self.type == InteractionType.APPLICATION_COMMAND

    @property
    def is_message_component(self) -> bool:
        """Indicates whether this interaction is a Message Component Interaction."""
        return self.type == InteractionType.MESSAGE_COMPONENT

    @property
    def is_autocomplete(self) -> bool:
        """Indicates whether this interaction is a Application Command Autocomplete Interaction."""
        return self.type == InteractionType.APPLICATION_COMMAND_AUTOCOMPLETE

    @property
    def is_modal_submit(self) -> bool:
        """Indicates whether this interaction is a Modal submit Interaction."""
        return self.type == InteractionType.MODAL_SUBMIT

    @property
    def is_responded(self) -> bool:
        """Indicates whether this interaction is responded."""
        return self._responded

is_application_command property

is_application_command: bool

Indicates whether this interaction is an Application Command Interaction.

is_autocomplete property

is_autocomplete: bool

Indicates whether this interaction is a Application Command Autocomplete Interaction.

is_message_component property

is_message_component: bool

Indicates whether this interaction is a Message Component Interaction.

is_modal_submit property

is_modal_submit: bool

Indicates whether this interaction is a Modal submit Interaction.

is_ping property

is_ping: bool

Indicates whether this interaction is a Ping Interaction.

is_responded property

is_responded: bool

Indicates whether this interaction is responded.