From fba3a079ddecb84de45cdfa8e10776fdfe812bd4 Mon Sep 17 00:00:00 2001 From: Sentry Date: Sun, 20 Nov 2016 21:30:48 +0100 Subject: [PATCH] [Audio] Fix [p]stop error when user is not in the channel (#480) --- cogs/audio.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/cogs/audio.py b/cogs/audio.py index 7bff9b108..eb2dd3879 100644 --- a/cogs/audio.py +++ b/cogs/audio.py @@ -1714,8 +1714,7 @@ class Audio: reply += " (%d%% out of %d%% needed)" % (vote, thresh) await self.bot.reply(reply) else: - await self.bot.reply("you aren't in the current playback" - " channel.") + await self.bot.say("You need to be in the voice channel to skip the music.") else: await self.bot.say("Can't skip if I'm not playing.") @@ -1732,6 +1731,7 @@ class Audio: is_admin = discord.utils.get(member.roles, name=admin_role) is not None is_mod = discord.utils.get(member.roles, name=mod_role) is not None + nonbots = sum(not m.bot for m in member.voice_channel.voice_members) alone = nonbots <= 1 @@ -1786,13 +1786,16 @@ class Audio: """Stops a currently playing song or playlist. CLEARS QUEUE.""" server = ctx.message.server if self.is_playing(server): - if self.can_instaskip(ctx.message.author): - await self.bot.say('Stopping...') - self._stop(server) + if ctx.message.author.voice_channel == server.me.voice_channel: + if self.can_instaskip(ctx.message.author): + await self.bot.say('Stopping...') + self._stop(server) + else: + await self.bot.say("You can't stop music when there are other" + " people in the channel! Vote to skip" + " instead.") else: - await self.bot.say("You can't stop music when there are other" - " people in the channel! Vote to skip" - " instead.") + await self.bot.say("You need to be in the voice channel to stop the music.") else: await self.bot.say("Can't stop if I'm not playing.") @@ -2081,7 +2084,7 @@ def verify_ffmpeg_avconv(): def setup(bot): check_folders() check_files() - + if youtube_dl is None: raise RuntimeError("You need to run `pip3 install youtube_dl`") if opus is False: @@ -2105,7 +2108,7 @@ def setup(bot): "and do ALL the steps in order.\n" "https://twentysix26.github.io/Red-Docs/\n" "".format(msg)) - + n = Audio(bot, player=player) # Praise 26 bot.add_cog(n) bot.add_listener(n.voice_state_update, 'on_voice_state_update')