Skip to content

Commit 3452445

Browse files
committed
🐛 Fix Interaction.channel incorrectly set
1 parent e4946ec commit 3452445

File tree

1 file changed

+28
-37
lines changed

1 file changed

+28
-37
lines changed

discord/interactions.py

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,10 @@ class Interaction:
119119
The interaction type.
120120
guild_id: Optional[:class:`int`]
121121
The guild ID the interaction was sent from.
122-
channel: Optional[Union[:class:`abc.GuildChannel`, :class:`abc.PrivateChannel`, :class:`Thread`]]
122+
channel: Optional[Union[:class:`abc.GuildChannel`, :class:`abc.PrivateChannel`, :class:`Thread`, :class:`PartialMessageable`]]
123123
The channel the interaction was sent from.
124+
125+
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.
124126
channel_id: Optional[:class:`int`]
125127
The ID of the channel the interaction was sent from.
126128
application_id: :class:`int`
@@ -261,20 +263,32 @@ def _from_data(self, data: InteractionPayload):
261263
except KeyError:
262264
pass
263265

264-
if channel := data.get("channel"):
265-
if (ch_type := channel.get("type")) is not None:
266-
factory, ch_type = _threaded_channel_factory(ch_type)
266+
channel = data.get("channel")
267+
data_ch_type: int | None = None
268+
if channel:
269+
data_ch_type = channel.get("type")
270+
271+
if data_ch_type is not None:
272+
factory, ch_type = _threaded_channel_factory(data_ch_type)
273+
if ch_type in (ChannelType.group, ChannelType.private):
274+
self.channel = factory(me=self.user, data=channel, state=self._state)
275+
elif self.guild:
276+
self.channel = self.guild._resolve_channel(self.channel_id) or factory(
277+
guild=self.guild, state=self._state, data=channel
278+
)
267279

268-
if ch_type in (ChannelType.group, ChannelType.private):
269-
self.channel = factory(
270-
me=self.user, data=channel, state=self._state
271-
)
272-
elif self.guild:
273-
self.channel = factory(
274-
guild=self.guild, state=self._state, data=channel
275-
)
276-
else:
277-
self.channel = self.cached_channel
280+
if self.channel is None and self.guild:
281+
self.channel = self.guild._resolve_channel(self.channel_id)
282+
if self.channel is None:
283+
if self.channel_id is not None:
284+
ch_type = (
285+
ChannelType.text
286+
if self.guild_id is not None
287+
else ChannelType.private
288+
)
289+
return PartialMessageable(
290+
state=self._state, id=self.channel_id, type=ch_type
291+
)
278292

279293
self._channel_data = channel
280294

@@ -305,29 +319,6 @@ def is_component(self) -> bool:
305319
"""Indicates whether the interaction is a message component."""
306320
return self.type == InteractionType.component
307321

308-
@utils.cached_slot_property("_cs_channel")
309-
def cached_channel(self) -> InteractionChannel | None:
310-
"""The channel the
311-
interaction was sent from.
312-
313-
Note that due to a Discord limitation, DM channels are not resolved since there is
314-
no data to complete them. These are :class:`PartialMessageable` instead.
315-
"""
316-
guild = self.guild
317-
channel = guild and guild._resolve_channel(self.channel_id)
318-
if channel is None:
319-
if self.channel_id is not None:
320-
type = (
321-
ChannelType.text
322-
if self.guild_id is not None
323-
else ChannelType.private
324-
)
325-
return PartialMessageable(
326-
state=self._state, id=self.channel_id, type=type
327-
)
328-
return None
329-
return channel
330-
331322
@property
332323
def permissions(self) -> Permissions:
333324
"""The resolved permissions of the member in the channel, including overwrites.

0 commit comments

Comments
 (0)