Skip to content

Commit

Permalink
Use the interaction user's guild as a fallback for Interaction.guild
Browse files Browse the repository at this point in the history
This ensures that the unavailable guild that is created within __init__
is used instead of constantly recreating it.
  • Loading branch information
Rapptz committed Aug 11, 2023
1 parent 44f9090 commit 2348d72
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ def client(self) -> ClientT:
@property
def guild(self) -> Optional[Guild]:
"""Optional[:class:`Guild`]: The guild the interaction was sent from."""
return self._state and self._state._get_guild(self.guild_id)
# The user.guild attribute is set in __init__ to the fallback guild if available
# Therefore, we can use that instead of recreating it every time this property is
# accessed
return (self._state and self._state._get_guild(self.guild_id)) or getattr(self.user, 'guild', None)

@property
def channel_id(self) -> Optional[int]:
Expand Down

0 comments on commit 2348d72

Please sign in to comment.