Use the interaction user's guild as a fallback for Interaction.guild

This ensures that the unavailable guild that is created within __init__
is used instead of constantly recreating it.
This commit is contained in:
Rapptz 2023-08-11 16:22:26 -04:00
parent 44f90909cb
commit 2348d72a72

View File

@ -254,7 +254,10 @@ class Interaction(Generic[ClientT]):
@property @property
def guild(self) -> Optional[Guild]: def guild(self) -> Optional[Guild]:
"""Optional[:class:`Guild`]: The guild the interaction was sent from.""" """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 @property
def channel_id(self) -> Optional[int]: def channel_id(self) -> Optional[int]: