Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
48 changes: 30 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,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

Expand Down Expand Up @@ -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 the interaction was sent from.
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