Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(state): prevent DeprecationWarning on shard reconnect #1267

Merged
merged 2 commits into from
Dec 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1267.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prevent :class:`py:DeprecationWarning` related to :attr:`Message.interaction` field on shard reconnect.
4 changes: 2 additions & 2 deletions disnake/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,8 +1446,8 @@ def _rebind_cached_references(self, new_guild: Guild, new_channel: GuildMessagea
# updated later in _update_member_references, after re-chunking
if isinstance(self.author, Member):
self.author.guild = new_guild
if self.interaction and isinstance(self.interaction.user, Member):
self.interaction.user.guild = new_guild
if self._interaction and isinstance(self._interaction.user, Member):
self._interaction.user.guild = new_guild

@utils.cached_slot_property("_cs_raw_mentions")
def raw_mentions(self) -> List[int]:
Expand Down
8 changes: 4 additions & 4 deletions disnake/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -2433,10 +2433,10 @@ def _update_member_references(self) -> None:
if new_author is not None and new_author is not msg.author:
msg.author = new_author

if msg.interaction is not None and isinstance(msg.interaction.user, Member):
new_author = msg.guild.get_member(msg.interaction.user.id)
if new_author is not None and new_author is not msg.interaction.user:
msg.interaction.user = new_author
if msg._interaction is not None and isinstance(msg._interaction.user, Member):
new_author = msg.guild.get_member(msg._interaction.user.id)
if new_author is not None and new_author is not msg._interaction.user:
msg._interaction.user = new_author

async def chunker(
self,
Expand Down
Loading