Access variables between commands with discord.py

后端 未结 2 723
执念已碎
执念已碎 2020-12-12 05:47

I have this (overly simplified) Discord bot

voting_enabled = False

@bot.command()
async def start():
    voting_enabled = True

@bot.command()
async def fin         


        
2条回答
  •  渐次进展
    2020-12-12 06:21

    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
    

提交回复
热议问题