Browse Source

Fix Message.channel rebinding sometimes being Object

pull/10109/head
Rapptz 2 years ago
committed by dolfies
parent
commit
5630d2b8f2
  1. 8
      discord/message.py
  2. 14
      discord/state.py

8
discord/message.py

@ -1646,9 +1646,13 @@ class Message(PartialMessage, Hashable):
def _handle_interaction(self, data: MessageInteractionPayload):
self.interaction = Interaction._from_message(self, **data)
def _rebind_cached_references(self, new_guild: Guild, new_channel: Union[TextChannel, Thread]) -> None:
def _rebind_cached_references(
self,
new_guild: Guild,
new_channel: Union[GuildChannel, Thread, PartialMessageable],
) -> None:
self.guild = new_guild
self.channel = new_channel
self.channel = new_channel # type: ignore # Not all "GuildChannel" are messageable at the moment
@utils.cached_slot_property('_cs_raw_mentions')
def raw_mentions(self) -> List[int]:

14
discord/state.py

@ -2674,6 +2674,20 @@ class ConnectionState:
def create_message(self, *, channel: MessageableChannel, data: MessagePayload) -> Message:
return Message(state=self, channel=channel, data=data)
def _update_message_references(self) -> None:
# self._messages won't be None when this is called
for msg in self._messages: # type: ignore
if not msg.guild:
continue
new_guild = self._get_guild(msg.guild.id)
if new_guild is not None and new_guild is not msg.guild:
channel_id = msg.channel.id
channel = new_guild._resolve_channel(channel_id) or PartialMessageable(
state=self, id=channel_id, guild_id=new_guild.id
)
msg._rebind_cached_references(new_guild, channel)
def create_integration_application(self, data: IntegrationApplicationPayload) -> IntegrationApplication:
return IntegrationApplication(state=self, data=data)

Loading…
Cancel
Save