Skip to content

Commit

Permalink
🐛 Fix Interaction.channel incorrectly set
Browse files Browse the repository at this point in the history
  • Loading branch information
Paillat-dev committed Nov 28, 2024
1 parent e4946ec commit 0fcf795
Showing 1 changed file with 18 additions and 28 deletions.
46 changes: 18 additions & 28 deletions discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down Expand Up @@ -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._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 @@ -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.
Expand Down

0 comments on commit 0fcf795

Please sign in to comment.