From 3452445dc12a3ebf41e7da19b6421e3225b4c253 Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 28 Nov 2024 09:34:56 +0100 Subject: [PATCH 1/8] :bug: Fix `Interaction.channel` incorrectly set --- discord/interactions.py | 65 ++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 37 deletions(-) diff --git a/discord/interactions.py b/discord/interactions.py index e7d7fade3e..e333d816f9 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` @@ -261,20 +263,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 @@ -305,29 +319,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. From 96a3141a13fd748b3653be2d816ead6bb996e7c1 Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 28 Nov 2024 09:44:24 +0100 Subject: [PATCH 2/8] :memo: CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9547fbafc..f61c46ca11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,6 +62,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2624](https://github.com/Pycord-Development/pycord/pull/2624)) - Fixed `AttributeError` when accessing `Member.guild_permissions` for user installed apps. ([#2650](https://github.com/Pycord-Development/pycord/pull/2650)) +- Fixed `Interaction.channel` was malformed. + ([#2658](https://github.com/Pycord-Development/pycord/pull/2658)) ### Changed From 188154706a1cac1e6a512ae6df965283c31ede80 Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 28 Nov 2024 18:50:41 +0100 Subject: [PATCH 3/8] :wastebasket: Deprecate instead of remove `cached_channel` --- discord/interactions.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/discord/interactions.py b/discord/interactions.py index e333d816f9..61f867753d 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -319,6 +319,29 @@ def is_component(self) -> bool: """Indicates whether the interaction is a message component.""" return self.type == InteractionType.component + @utils.cached_slot_property("_cs_channel") + @utils.deprecated("Interaction.channel", "2.7") + def cached_channel(self) -> InteractionChannel | None: + """The cached channel the interaction was sent from. + DM channels are not resolved. These are :class:`PartialMessageable` instead. + + .. deprecated:: 2.7 + """ + 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. From 37b5f50a7df44cf1caa646c3a043c49952031b4a Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 28 Nov 2024 19:07:00 +0100 Subject: [PATCH 4/8] :adhesive_bandage: Fix wrong `stacklevel` for deprecation warning. --- discord/interactions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/interactions.py b/discord/interactions.py index 61f867753d..c341314847 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -320,7 +320,7 @@ def is_component(self) -> bool: return self.type == InteractionType.component @utils.cached_slot_property("_cs_channel") - @utils.deprecated("Interaction.channel", "2.7") + @utils.deprecated("Interaction.channel", "2.7", stacklevel=4) def cached_channel(self) -> InteractionChannel | None: """The cached channel the interaction was sent from. DM channels are not resolved. These are :class:`PartialMessageable` instead. From 2d2de28524778146e6e986c8d58250393afda090 Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 28 Nov 2024 19:15:49 +0100 Subject: [PATCH 5/8] :memo: Wrong docstring. --- discord/interactions.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/discord/interactions.py b/discord/interactions.py index c341314847..5146fa3374 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -121,8 +121,6 @@ class Interaction: The guild ID the interaction was sent from. 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` From 7c816a4292a668bd40c071305e9aaed69f61cda6 Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 12 Dec 2024 13:14:22 +0100 Subject: [PATCH 6/8] :memo: Better CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f61c46ca11..288960d466 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -62,7 +62,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2624](https://github.com/Pycord-Development/pycord/pull/2624)) - Fixed `AttributeError` when accessing `Member.guild_permissions` for user installed apps. ([#2650](https://github.com/Pycord-Development/pycord/pull/2650)) -- Fixed `Interaction.channel` was malformed. +- Fixed malformed properties in `Interaction.channel`. ([#2658](https://github.com/Pycord-Development/pycord/pull/2658)) ### Changed From e5724dc8d8bebb1624522616a0eb0da1c759d48d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 16 Dec 2024 07:25:59 +0000 Subject: [PATCH 7/8] style(pre-commit): auto fixes from pre-commit.com hooks --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98670b9013..8082b797e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -66,7 +66,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#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 - Renamed `cover` property of `ScheduledEvent` and `cover` argument of From 9409c35da023acdfacf5050807b609c25e34efdd Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 18 Dec 2024 17:45:42 +0100 Subject: [PATCH 8/8] :pencil2: Fix writing --- discord/interactions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/interactions.py b/discord/interactions.py index 5146fa3374..17381f6180 100644 --- a/discord/interactions.py +++ b/discord/interactions.py @@ -320,7 +320,7 @@ def is_component(self) -> bool: @utils.cached_slot_property("_cs_channel") @utils.deprecated("Interaction.channel", "2.7", stacklevel=4) def cached_channel(self) -> InteractionChannel | None: - """The cached 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. .. deprecated:: 2.7