diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bda9a0ecc..8082b797e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,6 +64,8 @@ These changes are available on the `master` branch, but have not yet been releas apps. ([#2650](https://github.com/Pycord-Development/pycord/pull/2650)) - Fixed type annotations of cached properties. ([#2635](https://github.com/Pycord-Development/pycord/issues/2635)) +- Fixed malformed properties in `Interaction.channel`. + ([#2658](https://github.com/Pycord-Development/pycord/pull/2658)) ### Changed diff --git a/discord/interactions.py b/discord/interactions.py index e7d7fade3e..17381f6180 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -119,7 +119,7 @@ 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. channel_id: Optional[:class:`int`] The ID of the channel the interaction was sent from. @@ -261,20 +261,32 @@ def _from_data(self, data: InteractionPayload): except KeyError: pass - if channel := data.get("channel"): - if (ch_type := channel.get("type")) is not None: - factory, ch_type = _threaded_channel_factory(ch_type) + channel = data.get("channel") + data_ch_type: int | None = None + if channel: + data_ch_type = channel.get("type") + + if data_ch_type is not None: + factory, ch_type = _threaded_channel_factory(data_ch_type) + if ch_type in (ChannelType.group, ChannelType.private): + self.channel = factory(me=self.user, data=channel, state=self._state) + elif self.guild: + self.channel = self.guild._resolve_channel(self.channel_id) or factory( + guild=self.guild, state=self._state, data=channel + ) - if ch_type in (ChannelType.group, ChannelType.private): - self.channel = factory( - me=self.user, data=channel, state=self._state - ) - elif self.guild: - self.channel = factory( - guild=self.guild, state=self._state, data=channel - ) - else: - self.channel = self.cached_channel + if self.channel is None and self.guild: + self.channel = self.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 @@ -306,12 +318,12 @@ def is_component(self) -> bool: return self.type == InteractionType.component @utils.cached_slot_property("_cs_channel") + @utils.deprecated("Interaction.channel", "2.7", stacklevel=4) def cached_channel(self) -> InteractionChannel | None: - """The channel the - interaction was sent from. + """The cached channel from which the interaction was sent. + DM channels are not resolved. These are :class:`PartialMessageable` instead. - 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. + .. deprecated:: 2.7 """ guild = self.guild channel = guild and guild._resolve_channel(self.channel_id)