aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-08-10 09:28:14 -0400
committerRapptz <[email protected]>2021-08-10 09:28:14 -0400
commit66871f329e09b8df32f2be6f60fbe3433b9a03b1 (patch)
tree1db99205459a83eac1236c4e9b98579af51ab4a8
parentAdd support for PartialMessageable instances (diff)
downloaddiscord.py-66871f329e09b8df32f2be6f60fbe3433b9a03b1.tar.xz
discord.py-66871f329e09b8df32f2be6f60fbe3433b9a03b1.zip
Interaction.channel can be a PartialMessageable rather than Object
This allows it to work just fine in DMs
-rw-r--r--discord/interactions.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/discord/interactions.py b/discord/interactions.py
index 667c6773..7b49d44e 100644
--- a/discord/interactions.py
+++ b/discord/interactions.py
@@ -31,6 +31,7 @@ import asyncio
from . import utils
from .enums import try_enum, InteractionType, InteractionResponseType
from .errors import InteractionResponded, HTTPException, ClientException
+from .channel import PartialMessageable, ChannelType
from .user import User
from .member import Member
@@ -57,10 +58,12 @@ if TYPE_CHECKING:
from aiohttp import ClientSession
from .embeds import Embed
from .ui.view import View
- from .channel import VoiceChannel, StageChannel, TextChannel, CategoryChannel, StoreChannel
+ from .channel import VoiceChannel, StageChannel, TextChannel, CategoryChannel, StoreChannel, PartialMessageable
from .threads import Thread
- InteractionChannel = Union[VoiceChannel, StageChannel, TextChannel, CategoryChannel, StoreChannel, Thread]
+ InteractionChannel = Union[
+ VoiceChannel, StageChannel, TextChannel, CategoryChannel, StoreChannel, Thread, PartialMessageable
+ ]
MISSING: Any = utils.MISSING
@@ -111,6 +114,7 @@ class Interaction:
'_original_message',
'_cs_response',
'_cs_followup',
+ '_cs_channel',
)
def __init__(self, *, data: InteractionPayload, state: ConnectionState):
@@ -129,10 +133,9 @@ class Interaction:
self.guild_id: Optional[int] = utils._get_as_snowflake(data, 'guild_id')
self.application_id: int = int(data['application_id'])
- channel = self.channel or Object(id=self.channel_id) # type: ignore
self.message: Optional[Message]
try:
- self.message = Message(state=self._state, channel=channel, data=data['message']) # type: ignore
+ self.message = Message(state=self._state, channel=self.channel, data=data['message']) # type: ignore
except KeyError:
self.message = None
@@ -160,15 +163,21 @@ class Interaction:
"""Optional[:class:`Guild`]: The guild the interaction was sent from."""
return self._state and self._state._get_guild(self.guild_id)
- @property
+ @utils.cached_slot_property('_cs_channel')
def channel(self) -> Optional[InteractionChannel]:
- """Optional[Union[:class:`abc.GuildChannel`, :class:`Thread`]]: The channel the interaction was sent from.
+ """Optional[Union[:class:`abc.GuildChannel`, :class:`PartialMessageable`, :class:`Thread`]]: The channel the interaction was sent from.
Note that due to a Discord limitation, DM channels are not resolved since there is
- no data to complete them.
+ no data to complete them. These are :class:`PartialMessageable` instead.
"""
guild = self.guild
- return guild and guild._resolve_channel(self.channel_id)
+ channel = guild and guild._resolve_channel(self.channel_id)
+ if channel is None:
+ if self.channel_id is not None:
+ type = ChannelType.text if self.guild_id is not None else ChannelType.private
+ return PartialMessageable(state=self._state, id=self.channel_id, type=type)
+ return None
+ return channel
@property
def permissions(self) -> Permissions: