diff --git a/musicbot/cogs/music/__init__.py b/musicbot/cogs/music/__init__.py index 93e72a2..5088fd6 100644 --- a/musicbot/cogs/music/__init__.py +++ b/musicbot/cogs/music/__init__.py @@ -559,11 +559,18 @@ async def _forcedisconnect(self, ctx): try: player = self.get_player(ctx.guild) player.queue.clear() + # Hopefully helps + player.channel_id = None await player.stop() except Exception as e: self.logger.error("Error forcedisconnecting") self.logger.exception(e) - await ctx.voice_client.disconnect(force=True) + + if ctx.voice_client: + await ctx.voice_client.disconnect(force=True) + else: + self.logger.error("Voice client no longer exists") + embed = discord.Embed(description='{disconnect.disconnected}', color=ctx.me.color) embed = ctx.localizer.format_embed(embed) await ctx.send(embed=embed) diff --git a/musicbot/cogs/music/decorators.py b/musicbot/cogs/music/decorators.py index 5e8681f..856e439 100644 --- a/musicbot/cogs/music/decorators.py +++ b/musicbot/cogs/music/decorators.py @@ -1,6 +1,7 @@ import asyncio import functools import inspect +import logging import math import discord @@ -11,6 +12,8 @@ from . import music_errors from .voice_client import BasicVoiceClient +logger = logging.getLogger("musicbot").getChild("decorators") + def require_voice_connection(should_connect=False): """Checks if the bot is in a valid voice channel for the command @@ -50,9 +53,15 @@ async def ensure_voice_inner(self, ctx, *command_args, **kwargs): await ctx.author.voice.channel.connect(cls=BasicVoiceClient) elif player.channel_id and int(player.channel_id) != ctx.author.voice.channel.id: - bot_channel = self.bot.get_channel(int(player.channel_id)) - raise music_errors.UserInDifferentVoiceChannelError('You need to be in my voice channel', - channel=bot_channel) + if ctx.voice_client: + bot_channel = self.bot.get_channel(int(player.channel_id)) + raise music_errors.UserInDifferentVoiceChannelError('You need to be in my voice channel', + channel=bot_channel) + else: + # We are not connected anymore + logger.debug("Voice client no longer exists, clear voice state") + player.channel_id = None + player._voice_state.clear() await func(self, ctx, *command_args, **kwargs) diff --git a/requirements.txt b/requirements.txt index eba5d03..38f08f7 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ discord.py == 2.3.* -lavalink == 5.3.* +lavalink == 5.5.* asyncio pyyaml BeautifulSoup4