Added a couple more checks to voice, to catch when Discord says the connection was successful, yet it wasn't
This commit is contained in:
parent
540ecf86fb
commit
59c48b323e
1 changed files with 13 additions and 1 deletions
|
@ -146,6 +146,8 @@ class Music:
|
||||||
async def create_voice_client(self, channel):
|
async def create_voice_client(self, channel):
|
||||||
"""Creates a voice client and saves it"""
|
"""Creates a voice client and saves it"""
|
||||||
# First join the channel and get the VoiceClient that we'll use to save per server
|
# 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
|
server = channel.server
|
||||||
state = self.get_voice_state(server)
|
state = self.get_voice_state(server)
|
||||||
voice = self.bot.voice_client_in(server)
|
voice = self.bot.voice_client_in(server)
|
||||||
|
@ -154,17 +156,21 @@ class Music:
|
||||||
try:
|
try:
|
||||||
if voice is None:
|
if voice is None:
|
||||||
state.voice = await self.bot.join_voice_channel(channel)
|
state.voice = await self.bot.join_voice_channel(channel)
|
||||||
|
if state.voice:
|
||||||
return True
|
return True
|
||||||
elif voice.channel == channel:
|
elif voice.channel == channel:
|
||||||
state.voice = voice
|
state.voice = voice
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
# This shouldn't theoretically ever happen yet it does. Thanks Discord
|
||||||
await voice.disconnect()
|
await voice.disconnect()
|
||||||
state.voice = await self.bot.join_voice_channel(channel)
|
state.voice = await self.bot.join_voice_channel(channel)
|
||||||
return True
|
return True
|
||||||
except (discord.ClientException, socket.gaierror):
|
except (discord.ClientException, socket.gaierror):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
async def remove_voice_client(self, server):
|
async def remove_voice_client(self, server):
|
||||||
"""Removes any voice clients from a server
|
"""Removes any voice clients from a server
|
||||||
|
@ -413,6 +419,12 @@ class Music:
|
||||||
author_channel = ctx.message.author.voice.voice_channel
|
author_channel = ctx.message.author.voice.voice_channel
|
||||||
my_channel = ctx.message.server.me.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
|
# To try to avoid some abuse, ensure the requester is actually in our channel
|
||||||
if my_channel != author_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.")
|
await self.bot.say("You are not currently in the channel; please join before trying to request a song.")
|
||||||
|
|
Loading…
Reference in a new issue