1
0
Fork 0
mirror of synced 2024-05-18 19:42:28 +12:00

Handle an edge case with voice disconnection

This commit is contained in:
Phxntxm 2017-08-06 18:10:59 -05:00
parent f4ee4e81ae
commit 78afa83970

View file

@ -658,6 +658,21 @@ class Music:
if voice:
voice.stop()
await voice.disconnect(force=True)
# So discord has a weird case where the connection can be interrupted, and an auto-reconnect is attempted
# Auto-reconnects aren't handled for bot accounts, and this causes the bot to appear to be in the channel while it's actually not
# Since this means there is no connection (checked by voice being None) there's nothing to disconnect from
# So our workaround here is try to connect (this may timeout, and force it to now be visually disconnected) then disconnect
else:
if ctx.message.guild.me.voice:
try:
await ctx.message.guild.me.voice.channel.connect()
except asyncio.TimeoutError:
pass
else:
# Refresh the guild info, as want whatever the new VoiceClient is
guild = bot.get_guild(ctx.message.guild.id)
if guild.voice_client:
await guild.voice_client.disconnect(force=True)
@commands.command()
@commands.guild_only()