aboutsummaryrefslogtreecommitdiff
path: root/discord/interactions.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-04-08 02:12:55 -0400
committerRapptz <[email protected]>2021-04-08 02:12:55 -0400
commita31c19563fbda69f380d4b5f90939113995a6624 (patch)
tree0dfb94159e60b414de01756623a08a5b26264b47 /discord/interactions.py
parentAdd AllowedMentions typings (diff)
downloaddiscord.py-a31c19563fbda69f380d4b5f90939113995a6624.tar.xz
discord.py-a31c19563fbda69f380d4b5f90939113995a6624.zip
Add interaction related typings
Diffstat (limited to 'discord/interactions.py')
-rw-r--r--discord/interactions.py19
1 files changed, 14 insertions, 5 deletions
diff --git a/discord/interactions.py b/discord/interactions.py
index a235a0a6..ccdac792 100644
--- a/discord/interactions.py
+++ b/discord/interactions.py
@@ -25,6 +25,7 @@ DEALINGS IN THE SOFTWARE.
"""
from __future__ import annotations
+from typing import Optional, TYPE_CHECKING
from . import utils
from .enums import try_enum, InteractionType
@@ -33,6 +34,14 @@ __all__ = (
'Interaction',
)
+if TYPE_CHECKING:
+ from .types.interactions import (
+ Interaction as InteractionPayload,
+ )
+ from .guild import Guild
+ from .abc import GuildChannel
+
+
class Interaction:
"""Represents a Discord interaction.
@@ -60,6 +69,7 @@ class Interaction:
The token to continue the interaction. These are valid
for 15 minutes.
"""
+
__slots__ = (
'id',
'type',
@@ -73,11 +83,11 @@ class Interaction:
'_state',
)
- def __init__(self, *, data, state=None):
+ def __init__(self, *, data: InteractionPayload, state=None):
self._state = state
self._from_data(data)
- def _from_data(self, data):
+ def _from_data(self, data: InteractionPayload):
self.id = int(data['id'])
self.type = try_enum(InteractionType, data['type'])
self.data = data.get('data')
@@ -88,12 +98,12 @@ class Interaction:
self.application_id = utils._get_as_snowflake(data, 'application_id')
@property
- def guild(self):
+ def guild(self) -> Optional[Guild]:
"""Optional[:class:`Guild`]: The guild the interaction was sent from."""
return self._state and self._state.get_guild(self.guild_id)
@property
- def channel(self):
+ def channel(self) -> Optional[GuildChannel]:
"""Optional[:class:`abc.GuildChannel`]: The channel the interaction was sent from.
Note that due to a Discord limitation, DM channels are not resolved since there is
@@ -101,4 +111,3 @@ class Interaction:
"""
guild = self.guild
return guild and guild.get_channel(self.channel_id)
-