Fix Interaction.channel being None in threads
This commit is contained in:
parent
d001b9d0ee
commit
2d597e310b
@ -586,6 +586,12 @@ class Guild(Hashable):
|
|||||||
channels.sort(key=lambda c: (c._sorting_bucket, c.position, c.id))
|
channels.sort(key=lambda c: (c._sorting_bucket, c.position, c.id))
|
||||||
return as_list
|
return as_list
|
||||||
|
|
||||||
|
def _resolve_channel(self, id: Optional[int], /) -> Optional[Union[GuildChannel, Thread]]:
|
||||||
|
if id is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
return self._channels.get(id) or self._threads.get(id)
|
||||||
|
|
||||||
def get_channel(self, channel_id: int, /) -> Optional[GuildChannel]:
|
def get_channel(self, channel_id: int, /) -> Optional[GuildChannel]:
|
||||||
"""Returns a channel with the given ID.
|
"""Returns a channel with the given ID.
|
||||||
|
|
||||||
|
@ -47,11 +47,14 @@ if TYPE_CHECKING:
|
|||||||
Interaction as InteractionPayload,
|
Interaction as InteractionPayload,
|
||||||
)
|
)
|
||||||
from .guild import Guild
|
from .guild import Guild
|
||||||
from .abc import GuildChannel
|
|
||||||
from .state import ConnectionState
|
from .state import ConnectionState
|
||||||
from aiohttp import ClientSession
|
from aiohttp import ClientSession
|
||||||
from .embeds import Embed
|
from .embeds import Embed
|
||||||
from .ui.view import View
|
from .ui.view import View
|
||||||
|
from .channel import VoiceChannel, StageChannel, TextChannel, CategoryChannel, StoreChannel
|
||||||
|
from .threads import Thread
|
||||||
|
|
||||||
|
InteractionChannel = Union[VoiceChannel, StageChannel, TextChannel, CategoryChannel, StoreChannel, Thread]
|
||||||
|
|
||||||
MISSING: Any = utils.MISSING
|
MISSING: Any = utils.MISSING
|
||||||
|
|
||||||
@ -145,14 +148,14 @@ class Interaction:
|
|||||||
return self._state and self._state._get_guild(self.guild_id)
|
return self._state and self._state._get_guild(self.guild_id)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def channel(self) -> Optional[GuildChannel]:
|
def channel(self) -> Optional[InteractionChannel]:
|
||||||
"""Optional[:class:`abc.GuildChannel`]: The channel the interaction was sent from.
|
"""Optional[Union[:class:`abc.GuildChannel`, :class:`Thread`]]: The channel the interaction was sent from.
|
||||||
|
|
||||||
Note that due to a Discord limitation, DM channels are not resolved since there is
|
Note that due to a Discord limitation, DM channels are not resolved since there is
|
||||||
no data to complete them.
|
no data to complete them.
|
||||||
"""
|
"""
|
||||||
guild = self.guild
|
guild = self.guild
|
||||||
return guild and guild.get_channel(self.channel_id)
|
return guild and guild._resolve_channel(self.channel_id)
|
||||||
|
|
||||||
@utils.cached_slot_property('_cs_response')
|
@utils.cached_slot_property('_cs_response')
|
||||||
def response(self) -> InteractionResponse:
|
def response(self) -> InteractionResponse:
|
||||||
|
@ -383,7 +383,7 @@ class ConnectionState:
|
|||||||
channel = DMChannel._from_message(self, channel_id)
|
channel = DMChannel._from_message(self, channel_id)
|
||||||
guild = None
|
guild = None
|
||||||
else:
|
else:
|
||||||
channel = guild and (guild.get_channel(channel_id) or guild.get_thread(channel_id))
|
channel = guild and guild._resolve_channel(channel_id)
|
||||||
|
|
||||||
return channel or Object(id=channel_id), guild
|
return channel or Object(id=channel_id), guild
|
||||||
|
|
||||||
@ -1254,7 +1254,7 @@ class ConnectionState:
|
|||||||
return pm
|
return pm
|
||||||
|
|
||||||
for guild in self.guilds:
|
for guild in self.guilds:
|
||||||
channel = guild.get_channel(id) or guild.get_thread(id)
|
channel = guild._resolve_channel(id)
|
||||||
if channel is not None:
|
if channel is not None:
|
||||||
return channel
|
return channel
|
||||||
|
|
||||||
@ -1276,7 +1276,7 @@ class AutoShardedConnectionState(ConnectionState):
|
|||||||
new_guild = self._get_guild(msg.guild.id)
|
new_guild = self._get_guild(msg.guild.id)
|
||||||
if new_guild is not None and new_guild is not msg.guild:
|
if new_guild is not None and new_guild is not msg.guild:
|
||||||
channel_id = msg.channel.id
|
channel_id = msg.channel.id
|
||||||
channel = new_guild.get_channel(channel_id) or new_guild.get_thread(channel_id) or Object(id=channel_id)
|
channel = new_guild._resolve_channel(channel_id) or Object(id=channel_id)
|
||||||
msg._rebind_cached_references(new_guild, channel)
|
msg._rebind_cached_references(new_guild, channel)
|
||||||
|
|
||||||
async def chunker(self, guild_id, query='', limit=0, presences=False, *, shard_id=None, nonce=None):
|
async def chunker(self, guild_id, query='', limit=0, presences=False, *, shard_id=None, nonce=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user