diff --git a/discord/message.py b/discord/message.py index e371a3cfe..16e893a16 100644 --- a/discord/message.py +++ b/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]: diff --git a/discord/state.py b/discord/state.py index 9dadafeac..e54417cf4 100644 --- a/discord/state.py +++ b/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)