Browse Source

Add self_deaf and self_mute params to voice connect methods

pull/10109/head
Vaskel 3 years ago
committed by dolfies
parent
commit
2127d37a21
  1. 12
      discord/abc.py
  2. 20
      discord/voice_client.py
  3. 5
      docs/migrating.rst

12
discord/abc.py

@ -2056,6 +2056,8 @@ class Connectable(Protocol):
reconnect: bool = True,
cls: Callable[[Client, Connectable], T] = MISSING,
_channel: Optional[Connectable] = None,
self_deaf: bool = False,
self_mute: bool = False,
) -> T:
"""|coro|
@ -2073,6 +2075,14 @@ class Connectable(Protocol):
cls: Type[:class:`~discord.VoiceProtocol`]
A type that subclasses :class:`~discord.VoiceProtocol` to connect with.
Defaults to :class:`~discord.VoiceClient`.
self_mute: :class:`bool`
Indicates if the client should be self-muted.
.. versionadded: 2.0
self_deaf: :class:`bool`
Indicates if the client should be self-deafened.
.. versionadded: 2.0
Raises
-------
@ -2109,7 +2119,7 @@ class Connectable(Protocol):
state._add_voice_client(key_id, voice)
try:
await voice.connect(timeout=timeout, reconnect=reconnect)
await voice.connect(timeout=timeout, reconnect=reconnect, self_deaf=self_deaf, self_mute=self_mute)
except asyncio.TimeoutError:
try:
await voice.disconnect(force=True)

20
discord/voice_client.py

@ -149,7 +149,7 @@ class VoiceProtocol:
"""
raise NotImplementedError
async def connect(self, *, timeout: float, reconnect: bool) -> None:
async def connect(self, *, timeout: float, reconnect: bool, self_deaf: bool = False, self_mute: bool = False) -> None:
"""|coro|
An abstract method called when the client initiates the connection request.
@ -169,6 +169,14 @@ class VoiceProtocol:
The timeout for the connection.
reconnect: :class:`bool`
Whether reconnection is expected.
self_mute: :class:`bool`
Indicates if the client should be self-muted.
.. versionadded: 2.0
self_deaf: :class:`bool`
Indicates if the client should be self-deafened.
.. versionadded: 2.0
"""
raise NotImplementedError
@ -339,12 +347,12 @@ class VoiceClient(VoiceProtocol):
self._voice_server_complete.set()
async def voice_connect(self) -> None:
async def voice_connect(self, self_deaf: bool = False, self_mute: bool = False) -> None:
channel = self.channel
if self.guild:
await self.guild.change_voice_state(channel=channel)
await self.guild.change_voice_state(channel=channel, self_deaf=self_deaf, self_mute=self_mute)
else:
await self._state.client.change_voice_state(channel=channel)
await self._state.client.change_voice_state(channel=channel, self_deaf=self_deaf, self_mute=self_mute)
async def voice_disconnect(self) -> None:
guild = self.guild
@ -379,7 +387,7 @@ class VoiceClient(VoiceProtocol):
self._connected.set()
return ws
async def connect(self, *, reconnect: bool, timeout: float) -> None:
async def connect(self, *, reconnect: bool, timeout: float, self_deaf: bool = False, self_mute: bool = False) -> None:
_log.info('Connecting to voice...')
self.timeout = timeout
@ -393,7 +401,7 @@ class VoiceClient(VoiceProtocol):
]
# Start the connection flow
await self.voice_connect()
await self.voice_connect(self_deaf=self_deaf, self_mute=self_mute)
try:
await utils.sane_wait_for(futures, timeout=timeout)

5
docs/migrating.rst

@ -1090,6 +1090,11 @@ The following changes have been made:
- :attr:`File.filename` will no longer be ``None``, in situations where previously this was the case the filename is set to `'untitled'`.
:meth:`VoiceProtocol.connect` signature changes.
--------------------------------------------------
:meth:`VoiceProtocol.connect` will now be passed 2 keyword only arguments, ``self_deaf`` and ``self_mute``. These indicate
whether or not the client should join the voice chat being deafened or muted.
.. _migrating_2_0_commands:

Loading…
Cancel
Save