From de7d08ee755015c4e21656efe477ead26daa047f Mon Sep 17 00:00:00 2001 From: aikaterna <20862007+aikaterna@users.noreply.github.com> Date: Tue, 2 Apr 2019 19:22:57 -0700 Subject: [PATCH] [Audio] Match v2 behavior for channel change (#2521) * [Audio] Match v2 behavior for channel change * Use move_to instead of connect --- redbot/cogs/audio/audio.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/redbot/cogs/audio/audio.py b/redbot/cogs/audio/audio.py index cbc4d4de4..f4ff62fb6 100644 --- a/redbot/cogs/audio/audio.py +++ b/redbot/cogs/audio/audio.py @@ -2833,6 +2833,7 @@ class Audio(commands.Cog): ) is_mod = discord.utils.get(ctx.guild.get_member(member.id).roles, id=mod_role) is not None is_bot = member.bot is True + is_other_channel = await self._channel_check(ctx) return ( is_active_dj @@ -2842,6 +2843,7 @@ class Audio(commands.Cog): or is_admin or is_mod or is_bot + or is_other_channel ) async def _is_alone(self, ctx, member): @@ -3092,6 +3094,32 @@ class Audio(commands.Cog): self._restart_connect() + async def _channel_check(self, ctx): + player = lavalink.get_player(ctx.guild.id) + try: + in_channel = sum( + not m.bot for m in ctx.guild.get_member(self.bot.user.id).voice.channel.members + ) + except AttributeError: + return False + + if not ctx.author.voice: + user_channel = None + else: + user_channel = ctx.author.voice.channel + + if in_channel == 0 and user_channel: + if ( + (player.channel != user_channel) + and not player.current + and player.position == 0 + and len(player.queue) == 0 + ): + await player.move_to(user_channel) + return True + else: + return False + async def _check_api_tokens(self): spotify = await self.bot.db.api_tokens.get_raw( "spotify", default={"client_id": "", "client_secret": ""}