Skip to content

Commit 24c1a8e

Browse files
Paillat-devpre-commit-ci[bot]Lulalaby
authored
fix: 🐛 Fix Interaction.channel incorrectly set (#2658)
Signed-off-by: Paillat <me@paillat.dev> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Lala Sabathil <lala@pycord.dev>
1 parent f107660 commit 24c1a8e

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ These changes are available on the `master` branch, but have not yet been releas
7373
apps. ([#2650](https://github.com/Pycord-Development/pycord/pull/2650))
7474
- Fixed type annotations of cached properties.
7575
([#2635](https://github.com/Pycord-Development/pycord/issues/2635))
76+
- Fixed malformed properties in `Interaction.channel`.
77+
([#2658](https://github.com/Pycord-Development/pycord/pull/2658))
7678
- Fixed an error when responding non-ephemerally with a `Paginator` to an ephemerally
7779
deferred interaction.
7880
([#2661](https://github.com/Pycord-Development/pycord/pull/2661))

discord/interactions.py

+21-18
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ 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.
124124
channel_id: Optional[:class:`int`]
125125
The ID of the channel the interaction was sent from.
@@ -261,20 +261,23 @@ def _from_data(self, data: InteractionPayload):
261261
except KeyError:
262262
pass
263263

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)
264+
channel = data.get("channel")
265+
data_ch_type: int | None = channel.get("type") if channel else None
267266

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
267+
if data_ch_type is not None:
268+
factory, ch_type = _threaded_channel_factory(data_ch_type)
269+
if ch_type in (ChannelType.group, ChannelType.private):
270+
self.channel = factory(me=self.user, data=channel, state=self._state)
271+
272+
if self.channel is None and self.guild:
273+
self.channel = self.guild._resolve_channel(self.channel_id)
274+
if self.channel is None and self.channel_id is not None:
275+
ch_type = (
276+
ChannelType.text if self.guild_id is not None else ChannelType.private
277+
)
278+
self.channel = PartialMessageable(
279+
state=self._state, id=self.channel_id, type=ch_type
280+
)
278281

279282
self._channel_data = channel
280283

@@ -306,12 +309,12 @@ def is_component(self) -> bool:
306309
return self.type == InteractionType.component
307310

308311
@utils.cached_slot_property("_cs_channel")
312+
@utils.deprecated("Interaction.channel", "2.7", stacklevel=4)
309313
def cached_channel(self) -> InteractionChannel | None:
310-
"""The channel the
311-
interaction was sent from.
314+
"""The cached channel from which the interaction was sent.
315+
DM channels are not resolved. These are :class:`PartialMessageable` instead.
312316
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.
317+
.. deprecated:: 2.7
315318
"""
316319
guild = self.guild
317320
channel = guild and guild._resolve_channel(self.channel_id)

0 commit comments

Comments
 (0)