Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(member): implement new voice states endpoints #1217

Merged
merged 18 commits into from
Nov 29, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
31 changes: 31 additions & 0 deletions disnake/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -4673,6 +4673,37 @@ 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:
Snipy7374 marked this conversation as resolved.
Show resolved Hide resolved
"""|coro|

Fetches the :class:`VoiceState` of the member.

.. versionadded:: 2.10
Snipy7374 marked this conversation as resolved.
Show resolved Hide resolved

Raises
Snipy7374 marked this conversation as resolved.
Show resolved Hide resolved
------
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
Loading