Skip to content

Commit

Permalink
Merge branch 'master' into feat/flag-eq
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv authored Nov 29, 2024
2 parents da71473 + bb65a60 commit 3e8cb9e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog/1216.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add :meth:`Guild.fetch_voice_state` to fetch the :class:`VoiceState` of a member.
40 changes: 40 additions & 0 deletions disnake/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -4673,6 +4673,46 @@ async def fetch_voice_regions(self) -> List[VoiceRegion]:
data = await self._state.http.get_guild_voice_regions(self.id)
return [VoiceRegion(data=region) for region in data]

async def fetch_voice_state(self, member_id: int, /) -> VoiceState:
"""|coro|
Fetches the :class:`VoiceState` of a member.
.. note::
This method is an API call. For general usage, consider :attr:`Member.voice` instead.
.. versionadded:: 2.10
Parameters
----------
member_id: :class:`int`
The ID of the member.
Raises
------
NotFound
The member for which you tried to fetch a voice state is not
connected to a channel in this guild.
Forbidden
You do not have permission to fetch the member's voice state.
HTTPException
Fetching the voice state failed.
Returns
-------
:class:`VoiceState`
The voice state of the member.
"""
if member_id == self.me.id:
data = await self._state.http.get_my_voice_state(self.id)
else:
data = await self._state.http.get_voice_state(self.id, member_id)

channel_id = utils._get_as_snowflake(data, "channel_id")
channel: Optional[VocalGuildChannel] = self.get_channel(channel_id) # type: ignore
return VoiceState(data=data, channel=channel)

async def change_voice_state(
self, *, channel: Optional[Snowflake], self_mute: bool = False, self_deaf: bool = False
) -> None:
Expand Down
11 changes: 11 additions & 0 deletions disnake/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,17 @@ def change_nickname(
}
return self.request(r, json=payload, reason=reason)

def get_my_voice_state(self, guild_id: Snowflake) -> Response[voice.GuildVoiceState]:
return self.request(Route("GET", "/guilds/{guild_id}/voice-states/@me", guild_id=guild_id))

def get_voice_state(
self, guild_id: Snowflake, user_id: Snowflake
) -> Response[voice.GuildVoiceState]:
r = Route(
"GET", "/guilds/{guild_id}/voice-states/{user_id}", guild_id=guild_id, user_id=user_id
)
return self.request(r)

def edit_my_voice_state(self, guild_id: Snowflake, payload: Dict[str, Any]) -> Response[None]:
r = Route("PATCH", "/guilds/{guild_id}/voice-states/@me", guild_id=guild_id)
return self.request(r, json=payload)
Expand Down

0 comments on commit 3e8cb9e

Please sign in to comment.