Allow Message.channel to be a thread
This commit is contained in:
parent
51cc7622a6
commit
ac95b8b85b
@ -493,6 +493,10 @@ class Guild(Hashable):
|
|||||||
def get_channel(self, channel_id):
|
def get_channel(self, channel_id):
|
||||||
"""Returns a channel with the given ID.
|
"""Returns a channel with the given ID.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
This does *not* search for threads.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
-----------
|
-----------
|
||||||
channel_id: :class:`int`
|
channel_id: :class:`int`
|
||||||
|
@ -80,6 +80,7 @@ __all__ = (
|
|||||||
'DeletedReferencedMessage',
|
'DeletedReferencedMessage',
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def convert_emoji_reaction(emoji):
|
def convert_emoji_reaction(emoji):
|
||||||
if isinstance(emoji, Reaction):
|
if isinstance(emoji, Reaction):
|
||||||
emoji = emoji.emoji
|
emoji = emoji.emoji
|
||||||
@ -513,8 +514,8 @@ class Message(Hashable):
|
|||||||
This is not stored long term within Discord's servers and is only used ephemerally.
|
This is not stored long term within Discord's servers and is only used ephemerally.
|
||||||
embeds: List[:class:`Embed`]
|
embeds: List[:class:`Embed`]
|
||||||
A list of embeds the message has.
|
A list of embeds the message has.
|
||||||
channel: Union[:class:`TextChannel`, :class:`DMChannel`, :class:`GroupChannel`]
|
channel: Union[:class:`TextChannel`, :class:`Thread`, :class:`DMChannel`, :class:`GroupChannel`]
|
||||||
The :class:`TextChannel` that the message was sent from.
|
The :class:`TextChannel` or :class:`Thread` that the message was sent from.
|
||||||
Could be a :class:`DMChannel` or :class:`GroupChannel` if it's a private message.
|
Could be a :class:`DMChannel` or :class:`GroupChannel` if it's a private message.
|
||||||
reference: Optional[:class:`~discord.MessageReference`]
|
reference: Optional[:class:`~discord.MessageReference`]
|
||||||
The message that this message references. This is only applicable to messages of
|
The message that this message references. This is only applicable to messages of
|
||||||
@ -632,7 +633,7 @@ class Message(Hashable):
|
|||||||
self,
|
self,
|
||||||
*,
|
*,
|
||||||
state: ConnectionState,
|
state: ConnectionState,
|
||||||
channel: Union[TextChannel, DMChannel, GroupChannel],
|
channel: Union[TextChannel, Thread, DMChannel, GroupChannel],
|
||||||
data: MessagePayload,
|
data: MessagePayload,
|
||||||
):
|
):
|
||||||
self._state = state
|
self._state = state
|
||||||
@ -850,7 +851,7 @@ class Message(Hashable):
|
|||||||
def _handle_components(self, components: List[ComponentPayload]):
|
def _handle_components(self, components: List[ComponentPayload]):
|
||||||
self.components = [_component_factory(d) for d in components]
|
self.components = [_component_factory(d) for d in components]
|
||||||
|
|
||||||
def _rebind_channel_reference(self, new_channel: Union[TextChannel, DMChannel, GroupChannel]) -> None:
|
def _rebind_channel_reference(self, new_channel: Union[TextChannel, Thread, DMChannel, GroupChannel]) -> None:
|
||||||
self.channel = new_channel
|
self.channel = new_channel
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -380,7 +380,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)
|
channel = guild and (guild.get_channel(channel_id) or guild.get_thread(channel_id))
|
||||||
|
|
||||||
return channel or Object(id=channel_id), guild
|
return channel or Object(id=channel_id), guild
|
||||||
|
|
||||||
@ -1181,7 +1181,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 Object(id=channel_id)
|
channel = new_guild.get_channel(channel_id) or new_guild.get_thread(channel_id) or Object(id=channel_id)
|
||||||
msg._rebind_channel_reference(channel)
|
msg._rebind_channel_reference(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