I have this (overly simplified) Discord bot
voting_enabled = False
@bot.command()
async def start():
voting_enabled = True
@bot.command()
async def fin
The global keyword was not used correctly.
global should be defined within every function.
Example:
voting_enabled = False
@bot.command()
async def start():
global voting_enabled
voting_enabled = True
@bot.command()
async def finish():
global voting_enabled
voting_enabled = False
@bot.command()
async def vote():
global voting_enabled
if voting_enabled:
# Do something
else:
# Do something else
Except don't use globals because they stinky. Discord.py has another way to do this.
bot.voting_enabled = False
@bot.command()
async def start():
bot.voting_enabled = True
@bot.command()
async def finish():
bot.voting_enabled = False
@bot.command()
async def vote():
if bot.voting_enabled:
# Do something
else:
# Do something else