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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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:`Member.fetch_voice_state` to fetch the :class:`VoiceState` of a member.
12 changes: 12 additions & 0 deletions disnake/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,6 +935,18 @@ def change_nickname(
}
return self.request(r, json=payload, reason=reason)

def get_my_voice_state(self, guild_id: Snowflake) -> Response[voice.GuildVoiceState]:
r = Route("GET", "/guilds/{guild_id}/voice-states/@me", guild_id=guild_id)
return self.request(r)
Snipy7374 marked this conversation as resolved.
Show resolved Hide resolved

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
33 changes: 33 additions & 0 deletions disnake/member.py
Original file line number Diff line number Diff line change
Expand Up @@ -1004,6 +1004,39 @@ async def edit(
data = await http.edit_member(guild_id, self.id, reason=reason, **payload)
return Member(data=data, guild=self.guild, state=self._state)

async def fetch_voice_state(self, *, cache: bool) -> VoiceState:
"""|coro|

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

.. versionadded:: 2.10

Parameters
----------
cache: :class:`bool`
Whether to cache the fetched voice state.
Snipy7374 marked this conversation as resolved.
Show resolved Hide resolved

Raises
------
NotFound
The member for which you tried to fetch a voice state is not
connected to a channel.
Snipy7374 marked this conversation as resolved.
Show resolved Hide resolved

Returns
-------
:class:`VoiceState`
The voice state of the member.
"""
data = await self._state.http.get_voice_state(self.guild.id, self.id)
channel_id = utils._get_as_snowflake(data, "channel_id")

if cache:
_, _, after = self.guild._update_voice_state(data, channel_id)
return after

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

async def request_to_speak(self) -> None:
"""|coro|

Expand Down
Loading