[Audio] Match v2 behavior for channel change (#2521)

* [Audio] Match v2 behavior for channel change

* Use move_to instead of connect
This commit is contained in:
aikaterna 2019-04-02 19:22:57 -07:00 committed by Will
parent 2a486cad66
commit de7d08ee75

View File

@ -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": ""}