Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 Fix Interaction.channel incorrectly set #2658

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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 @@ -66,6 +66,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)
Dorukyum marked this conversation as resolved.
Show resolved Hide resolved
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
Loading