From 59c48b323e663ff033e115de6b432891d63773ef Mon Sep 17 00:00:00 2001 From: Phxntxm Date: Sun, 12 Feb 2017 16:31:18 -0600 Subject: [PATCH] Added a couple more checks to voice, to catch when Discord says the connection was successful, yet it wasn't --- cogs/music.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cogs/music.py b/cogs/music.py index 8e3e64f..5474ecc 100644 --- a/cogs/music.py +++ b/cogs/music.py @@ -146,6 +146,8 @@ class Music: async def create_voice_client(self, channel): """Creates a voice client and saves it""" # First join the channel and get the VoiceClient that we'll use to save per server + await self.remove_voice_client(channel.server) + server = channel.server state = self.get_voice_state(server) voice = self.bot.voice_client_in(server) @@ -154,17 +156,21 @@ class Music: try: if voice is None: state.voice = await self.bot.join_voice_channel(channel) - return True + if state.voice: + return True elif voice.channel == channel: state.voice = voice return True else: + # This shouldn't theoretically ever happen yet it does. Thanks Discord await voice.disconnect() state.voice = await self.bot.join_voice_channel(channel) return True except (discord.ClientException, socket.gaierror): continue + return False + async def remove_voice_client(self, server): """Removes any voice clients from a server @@ -413,6 +419,12 @@ class Music: author_channel = ctx.message.author.voice.voice_channel my_channel = ctx.message.server.me.voice.voice_channel + if my_channel is None: + # If we're here this means that after 3 attempts...4 different "failsafes"... + # Discord has returned saying the connection was successful, and returned a None connection + await self.bot.say("I failed to connect to the channel! Please try again soon") + return + # To try to avoid some abuse, ensure the requester is actually in our channel if my_channel != author_channel: await self.bot.say("You are not currently in the channel; please join before trying to request a song.")