From c32479dbe0ac9d15d386bccdbed6881ada9d7680 Mon Sep 17 00:00:00 2001 From: Damego Date: Wed, 4 Jan 2023 16:04:10 +0500 Subject: [PATCH] feat: Add `channel` & `guild` property for `VoiceState` --- interactions/api/models/gw.py | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/interactions/api/models/gw.py b/interactions/api/models/gw.py index 6e5dfbbfa..6d2a3218b 100644 --- a/interactions/api/models/gw.py +++ b/interactions/api/models/gw.py @@ -648,6 +648,21 @@ def joined(self) -> bool: """ return self.channel_id is not None + @property + def channel(self) -> Optional[Channel]: + """ + Returns the current channel, if cached. + """ + return self._client.cache[Channel].get(self.channel_id) + + @property + def guild(self) -> Optional[Guild]: + """ + Returns the current guild, if cached. + """ + + return self._client.cache[Guild].get(self.guild_id) + async def mute_member(self, reason: Optional[str] = None) -> Member: """ Mutes the current member. @@ -689,15 +704,21 @@ async def get_channel(self) -> Channel: :rtype: Channel """ - return Channel( - **await self._client.get_channel(int(self.channel_id)), - _client=self._client, - ) + if channel := self.channel: + return channel - async def get_guild(self) -> "Guild": + res = await self._client.get_channel(int(self.channel_id)) + return Channel(**res, _client=self._client) + + async def get_guild(self) -> Guild: """ Gets the guild in what the update took place. :rtype: Guild """ - return Guild(**await self._client.get_guild(int(self.guild_id)), _client=self._client) + + if guild := self.guild: + return guild + + res = await self._client.get_guild(int(self.guild_id)) + return Guild(**res, _client=self._client)