Skip to content

Commit

Permalink
fix: 🐛 Fix Interaction.channel incorrectly set (#2658)
Browse files Browse the repository at this point in the history

Signed-off-by: Paillat <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Lala Sabathil <[email protected]>
  • Loading branch information
3 people authored Jan 10, 2025
1 parent f107660 commit 24c1a8e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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))
- Fixed an error when responding non-ephemerally with a `Paginator` to an ephemerally
deferred interaction.
([#2661](https://github.com/Pycord-Development/pycord/pull/2661))
Expand Down
39 changes: 21 additions & 18 deletions discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -261,20 +261,23 @@ 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 = channel.get("type") if channel else None

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 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)

if self.channel is None and self.guild:
self.channel = self.guild._resolve_channel(self.channel_id)
if self.channel is None and self.channel_id is not None:
ch_type = (
ChannelType.text if self.guild_id is not None else ChannelType.private
)
self.channel = PartialMessageable(
state=self._state, id=self.channel_id, type=ch_type
)

self._channel_data = channel

Expand Down Expand Up @@ -306,12 +309,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)
Expand Down

0 comments on commit 24c1a8e

Please sign in to comment.