diff --git a/redbot/cogs/audio/core/commands/controller.py b/redbot/cogs/audio/core/commands/controller.py index 8cc9714697b..3c10a3e479e 100644 --- a/redbot/cogs/audio/core/commands/controller.py +++ b/redbot/cogs/audio/core/commands/controller.py @@ -30,6 +30,37 @@ class PlayerControllerCommands(MixinMeta, metaclass=CompositeMetaClass): @commands.bot_has_permissions(embed_links=True) async def command_disconnect(self, ctx: commands.Context): """Disconnect from the voice channel.""" + + player = lavalink.get_player(ctx.guild.id) + + # Check if the voice channel is empty except for the bot. + if ctx.guild.me.voice and len(ctx.guild.me.voice.channel.members) == 1: + await self.send_embed_msg(ctx, title=_("Disconnecting...")) + self.bot.dispatch("red_audio_audio_disconnect", ctx.guild) + self.update_player_lock(ctx, False) + eq = player.fetch("eq") + player.queue = [] + player.store("playing_song", None) + player.store("autoplay_notified", False) + if eq: + await self.config.custom("EQUALIZER", ctx.guild.id).eq_bands.set(eq.bands) + await player.stop() + await player.disconnect() + await self.config.guild_from_id(guild_id=ctx.guild.id).currently_auto_playing_in.set( + [] + ) + self._ll_guild_updates.discard(ctx.guild.id) + await self.api_interface.persistent_queue_api.drop(ctx.guild.id) + return await self.send_embed_msg( + ctx, title=_("Disconnected from empty voice channel.") + ) + + # Check if the user is in a voice channel or if the voice channel is empty except for the bot. + if ctx.author.voice is None and not ( + ctx.guild.me.voice and len(ctx.guild.me.voice.channel.members) == 1 + ): + return await self.send_embed_msg(ctx, title=_("You are not in a voice channel!")) + if not self._player_check(ctx): return await self.send_embed_msg(ctx, title=_("Nothing playing.")) else: @@ -37,7 +68,6 @@ async def command_disconnect(self, ctx: commands.Context): ctx.guild.id, await self.config.guild(ctx.guild).dj_enabled() ) vote_enabled = await self.config.guild(ctx.guild).vote_enabled() - player = lavalink.get_player(ctx.guild.id) can_skip = await self._can_instaskip(ctx, ctx.author) if ( (vote_enabled or (vote_enabled and dj_enabled)) @@ -61,7 +91,6 @@ async def command_disconnect(self, ctx: commands.Context): title=_("Unable to Disconnect"), description=_("You need the DJ role to disconnect."), ) - await self.send_embed_msg(ctx, title=_("Disconnecting...")) self.bot.dispatch("red_audio_audio_disconnect", ctx.guild) self.update_player_lock(ctx, False)