From 339e26275f79cbfa141da1b22aa6103234c7b35b Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 11 May 2016 20:34:37 -0400 Subject: [PATCH] Add VoiceClient.move_to for quick switching of voice channels. --- discord/voice_client.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/discord/voice_client.py b/discord/voice_client.py index 5da25684d..0826ad1ef 100644 --- a/discord/voice_client.py +++ b/discord/voice_client.py @@ -227,6 +227,32 @@ class VoiceClient: yield from self.ws.close() yield from self.main_ws.voice_state(self.guild_id, None, self_mute=True) + @asyncio.coroutine + def move_to(self, channel): + """|coro| + + Moves you to a different voice channel. + + .. warning:: + + :class:`Object` instances do not work with this function. + + Parameters + ----------- + channel : :class:`Channel` + The channel to move to. Must be a voice channel. + + Raises + ------- + InvalidArgument + Not a voice channel. + """ + + if str(getattr(channel, 'type', 'text')) != 'voice': + raise InvalidArgument('Must be a voice channel.') + + yield from self.main_ws.voice_state(self.guild_id, channel.id) + def is_connected(self): """bool : Indicates if the voice client is connected to voice.""" return self._connected.is_set()