I'm trying to solve a problem, I have many commands and events in my discord bot (minigames) and I want users to be able to use only one command at a time so if there is one minigame already running, other commands or events can't be used. So I created the on_command
variable and at the beginning of every command and event the variable changes to 1 and at the end of every command and event the variable changes back to 0. So if someone tries to use some command or event and the variable is 1, the bot just sends him that he can't use that command now. But for some reason, it doesn't work and I get the next error:
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: UnboundLocalError: local variable 'on_command' referenced before assignment
My code:
on_command = 0
@bot.command()
@commands.cooldown(1, 180.0, commands.BucketType.guild)
async def question(msg):
if msg.channel.id != channel:
return
if on_command == 1:
await msg.send("Another command or event is running")
return
on_command = 1
....
....
....
on_command = 0