From 57f495ae376c3e69aca6e043efb44870d908723f Mon Sep 17 00:00:00 2001 From: Jonas Leder Date: Mon, 28 Sep 2020 20:54:01 +0200 Subject: [PATCH] check if user is connected to voice channel, if using VC commands --- bot.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/bot.py b/bot.py index 642bc23..8fc3444 100644 --- a/bot.py +++ b/bot.py @@ -491,6 +491,11 @@ async def play(ctx, songURL : str): @bot.command(brief="skipps the current song in playlist") async def skip(ctx): + try: + channel = ctx.author.voice.channel#get the current voicechat the user is in + except:#if we can't get the voice channel, the user is not in one ==> print an error + await ctx.message.channel.send("To use the music bot you have to be in a voice chat") + return if reactOnValidCommand: await ctx.message.add_reaction("✅") global player# import the global variable player.stop()#stop the player (daemon think song enden ==> plays next one) @@ -510,6 +515,11 @@ async def que(ctx): @bot.command(brief="stop the music bot and clear the que") async def stop(ctx): if reactOnValidCommand: await ctx.message.add_reaction("✅") + try: + channel = ctx.author.voice.channel#get the current voicechat the user is in + except:#if we can't get the voice channel, the user is not in one ==> print an error + await ctx.message.channel.send("To use the music bot you have to be in a voice chat") + return global player#import the global variables global playerQue global titleQue @@ -533,6 +543,12 @@ async def stop(ctx): @bot.command(brief="changes the volume of the music bot")#with this command you can change the volume of the music bot async def volume(ctx, volume : int): if reactOnValidCommand: await ctx.message.add_reaction("✅") + try: + channel = ctx.author.voice.channel#get the current voicechat the user is in + except:#if we can't get the voice channel, the user is not in one ==> print an error + await ctx.message.channel.send("To use the music bot you have to be in a voice chat") + return + global audioPlayer#import hte global audio player if(volume < 0) or (volume > 100):#check if the volume is in a percent range ctx.message.channel.send("Volume has to be between 0 and 100")