mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-04 01:00:00 +00:00
Set Message.guild from guild_id if unavailable through Message.channel
This commit is contained in:
parent
e96df33ce0
commit
6b1d46a1ea
@ -590,6 +590,8 @@ class Message(Hashable):
|
|||||||
A list of components in the message.
|
A list of components in the message.
|
||||||
|
|
||||||
.. versionadded:: 2.0
|
.. versionadded:: 2.0
|
||||||
|
guild: Optional[:class:`Guild`]
|
||||||
|
The guild that the message belongs to, if applicable.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
@ -601,7 +603,6 @@ class Message(Hashable):
|
|||||||
'_cs_raw_channel_mentions',
|
'_cs_raw_channel_mentions',
|
||||||
'_cs_raw_role_mentions',
|
'_cs_raw_role_mentions',
|
||||||
'_cs_system_content',
|
'_cs_system_content',
|
||||||
'_cs_guild',
|
|
||||||
'tts',
|
'tts',
|
||||||
'content',
|
'content',
|
||||||
'channel',
|
'channel',
|
||||||
@ -623,6 +624,7 @@ class Message(Hashable):
|
|||||||
'activity',
|
'activity',
|
||||||
'stickers',
|
'stickers',
|
||||||
'components',
|
'components',
|
||||||
|
'guild',
|
||||||
)
|
)
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
@ -656,6 +658,11 @@ class Message(Hashable):
|
|||||||
self.stickers = [Sticker(data=d, state=state) for d in data.get('stickers', [])]
|
self.stickers = [Sticker(data=d, state=state) for d in data.get('stickers', [])]
|
||||||
self.components = [_component_factory(d) for d in data.get('components', [])]
|
self.components = [_component_factory(d) for d in data.get('components', [])]
|
||||||
|
|
||||||
|
try:
|
||||||
|
self.guild = channel.guild
|
||||||
|
except AttributeError:
|
||||||
|
self.guild = state._get_guild(utils._get_as_snowflake(data, 'guild_id'))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ref = data['message_reference']
|
ref = data['message_reference']
|
||||||
except KeyError:
|
except KeyError:
|
||||||
@ -851,19 +858,10 @@ 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, Thread, DMChannel, GroupChannel]) -> None:
|
def _rebind_cached_references(self, new_guild: Guild, new_channel: Union[TextChannel, Thread]) -> None:
|
||||||
|
self.guild = new_guild
|
||||||
self.channel = new_channel
|
self.channel = new_channel
|
||||||
|
|
||||||
try:
|
|
||||||
del self._cs_guild # type: ignore
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
@utils.cached_slot_property('_cs_guild')
|
|
||||||
def guild(self) -> Optional[Guild]:
|
|
||||||
"""Optional[:class:`Guild`]: The guild that the message belongs to, if applicable."""
|
|
||||||
return getattr(self.channel, 'guild', None)
|
|
||||||
|
|
||||||
@utils.cached_slot_property('_cs_raw_mentions')
|
@utils.cached_slot_property('_cs_raw_mentions')
|
||||||
def raw_mentions(self) -> List[int]:
|
def raw_mentions(self) -> List[int]:
|
||||||
"""List[:class:`int`]: A property that returns an array of user IDs matched with
|
"""List[:class:`int`]: A property that returns an array of user IDs matched with
|
||||||
|
@ -1277,7 +1277,7 @@ class AutoShardedConnectionState(ConnectionState):
|
|||||||
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.get_channel(channel_id) or new_guild.get_thread(channel_id) or Object(id=channel_id)
|
||||||
msg._rebind_channel_reference(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):
|
||||||
ws = self._get_websocket(guild_id, shard_id=shard_id)
|
ws = self._get_websocket(guild_id, shard_id=shard_id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user