def set_voice_client(self, voice_client: discord.VoiceClient): """Set new voice client to the state. If the same client is provided, does nothing. If other voice client is present, it will be removed and all playing audio sources will be immediately finished first. TODO: Hey, we can change voice client, that is owned by guild/channel with a voice client key != our voice client key. Do something! Args: voice_client: Voice client to set. Raises: ValueError: If not a :class:`discord.VoiceClient` provided, or voice client is not connected. """ if not isinstance(voice_client, discord.VoiceClient): raise ValueError("Not a voice client") if voice_client == self._voice_client: return if not voice_client.is_connected(): raise ValueError("Voice client is not connected") if self._voice_client is not None: self.remove_voice_client() self._loop = voice_client.loop self._voice_client = voice_client self._voice_client_disconnect_source = voice_client.disconnect voice_client.disconnect = self._on_disconnect log.debug(f"Voice client has set (Voice client key ID #{self._key_id})")
def disconnector(voice_client: discord.VoiceClient, bot: commands.Bot): """ This function is passed as the after parameter of FFmpegPCMAudio() as it does not take coroutines. Args: voice_client: The voice client that will be disconnected (discord.VoiceClient) bot: The bot that will terminate the voice client, which will be this very bot """ coro = voice_client.disconnect() fut = asyncio.run_coroutine_threadsafe(coro, bot.loop) try: fut.result() except asyncio.CancelledError: pass
def leaveVoice(self, _voice: discord.VoiceClient): coro = _voice.disconnect() fut = discord.compat.run_coroutine_threadsafe(coro, self.client.loop) fut.result()