From d9af48f84c69ad759c9cb91ac8a11b8a650bc2dc Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 28 Nov 2024 09:34:56 +0100 Subject: [PATCH] :bug: Fix `Interaction.channel` incorrectly set --- discord/interactions.py | 46 ++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 28 deletions(-) diff --git a/discord/interactions.py b/discord/interactions.py index e7d7fade3e..d108610906 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -119,8 +119,10 @@ class Interaction: The interaction type. guild_id: Optional[:class:`int`] The guild ID the interaction was sent from. - channel: Optional[Union[:class:`abc.GuildChannel`, :class:`abc.PrivateChannel`, :class:`Thread`]] + channel: Optional[Union[:class:`abc.GuildChannel`, :class:`abc.PrivateChannel`, :class:`Thread`, :class:`PartialMessageable`]] 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. These are :class:`PartialMessageable` instead. channel_id: Optional[:class:`int`] The ID of the channel the interaction was sent from. application_id: :class:`int` @@ -270,11 +272,22 @@ def _from_data(self, data: InteractionPayload): me=self.user, data=channel, state=self._state ) elif self.guild: - self.channel = factory( - guild=self.guild, state=self._state, data=channel - ) + self.channel = self.guild._resolve_channel( + self.channel_id + ) or factory(guild=self.guild, state=self._state, data=channel) else: - self.channel = self.cached_channel + if self.guild: + self.channel = self.guild and guild._resolve_channel(self.channel_id) + if self.channel is None: + if self.channel_id is not None: + ch_type = ( + ChannelType.text + if self.guild_id is not None + else ChannelType.private + ) + return PartialMessageable( + state=self._state, id=self.channel_id, type=ch_type + ) self._channel_data = channel @@ -305,29 +318,6 @@ def is_component(self) -> bool: """Indicates whether the interaction is a message component.""" return self.type == InteractionType.component - @utils.cached_slot_property("_cs_channel") - def cached_channel(self) -> InteractionChannel | None: - """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. These are :class:`PartialMessageable` instead. - """ - guild = self.guild - 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: """The resolved permissions of the member in the channel, including overwrites.