Skip to content

Commit 8d64c72

Browse files
committed
feat: use a PartialChannel object when the Channel of an interaction is in a guild but not cached
Signed-off-by: Mathieu Corsham <McCuber04@outlook.de>
1 parent 3298398 commit 8d64c72

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

discord/interactions.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from typing_extensions import Literal
3333

3434
from . import abc, utils
35-
from .channel import _channel_factory, DMChannel, TextChannel, ThreadChannel, VoiceChannel, ForumPost
35+
from .channel import _channel_factory, DMChannel, TextChannel, ThreadChannel, VoiceChannel, ForumPost, PartialMessageable
3636
from .components import *
3737
from .embeds import Embed
3838
from .enums import (
@@ -669,7 +669,8 @@ async def edit(
669669

670670
state = self._state
671671
if not self.channel:
672-
self.channel = self._state.add_dm_channel(data=await self._http.get_channel(self.channel_id))
672+
ch = await self._http.get_channel(self.channel_id)
673+
self.channel = _channel_factory(ch['type'])[0](state=state, data=ch)
673674

674675
if response_type is MISSING:
675676
params = handle_message_parameters(
@@ -978,8 +979,8 @@ def author(self) -> Union[Member, User]:
978979
return self.member if self.member is not None else self.user
979980

980981
@property
981-
def channel(self) -> Union[DMChannel, TextChannel, ThreadChannel, ForumPost, VoiceChannel]:
982-
"""Union[:class:`~discord.TextChannel`, :class:`~discord.ThreadChannel`, :class:`~discord.DMChannel`, :class:`~discord.VoiceChannel`]:
982+
def channel(self) -> Union[DMChannel, TextChannel, ThreadChannel, ForumPost, VoiceChannel, PartialMessageable]:
983+
"""Union[:class:`~discord.TextChannel`, :class:`~discord.ThreadChannel`, :class:`~discord.DMChannel`, :class:`~discord.VoiceChannel`, :class:`~discord.ForumPost`, :class:`~discord.PartialMessageable`
983984
The channel where the interaction was invoked in.
984985
"""
985986
return getattr(self, '_channel', self.guild.get_channel(self.channel_id) if self.guild_id else self._state.get_channel(self.channel_id))

discord/state.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ def parse_interaction_create(self, data):
592592
interaction = BaseInteraction.from_type(state=self, data=data)
593593
interaction.user = self.store_user(interaction._user)
594594
if interaction.guild_id:
595-
interaction.channel = interaction.guild.get_channel(interaction.channel_id)
595+
interaction.channel = interaction.guild.get_channel(interaction.channel_id) or PartialMessageable(id=interaction.channel_id, state=self)
596596
interaction.member = interaction.guild.get_member(interaction.user_id)
597597
if interaction.member is None:
598598
# This can only be the case if ``GUILD_MEMBERS`` Intents are not enabled or the member is not in the cache right now.

0 commit comments

Comments
 (0)