mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-07 12:18:59 +00:00
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:
parent
44f90909cb
commit
2348d72a72
@ -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]:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user