From 89b9f1616ca060bfc44e562330bf30bffe9419f1 Mon Sep 17 00:00:00 2001 From: Vaskel <49348256+ImVaskel@users.noreply.github.com> Date: Thu, 14 Apr 2022 19:06:22 -0400 Subject: [PATCH] Add self_deaf and self_mute params to voice connect methods --- discord/abc.py | 12 +++++++++++- discord/voice_client.py | 18 +++++++++++++----- docs/migrating.rst | 5 +++++ 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/discord/abc.py b/discord/abc.py index 389466440..5344e0a04 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -1783,6 +1783,8 @@ class Connectable(Protocol): timeout: float = 60.0, reconnect: bool = True, cls: Callable[[Client, Connectable], T] = MISSING, + self_deaf: bool = False, + self_mute: bool = False, ) -> T: """|coro| @@ -1802,6 +1804,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 ------- @@ -1838,7 +1848,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) diff --git a/discord/voice_client.py b/discord/voice_client.py index 02098832a..062b26377 100644 --- a/discord/voice_client.py +++ b/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,8 +347,8 @@ class VoiceClient(VoiceProtocol): self._voice_server_complete.set() - async def voice_connect(self) -> None: - await self.channel.guild.change_voice_state(channel=self.channel) + async def voice_connect(self, self_deaf: bool = False, self_mute: bool = False) -> None: + await self.channel.guild.change_voice_state(channel=self.channel, self_deaf=self_deaf, self_mute=self_mute) async def voice_disconnect(self) -> None: _log.info('The voice handshake is being terminated for Channel ID %s (Guild ID %s)', self.channel.id, self.guild.id) @@ -367,7 +375,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 @@ -381,7 +389,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) diff --git a/docs/migrating.rst b/docs/migrating.rst index aad1d9b1c..8912092bb 100644 --- a/docs/migrating.rst +++ b/docs/migrating.rst @@ -1212,6 +1212,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: