如何仅在boolean为true时运行discord.py命令



所以我正试图为我的discord机器人制作一个琐事命令。我想让它在你输入答案时不能再不回答了。我试过这样的东西:

import discord
from discord.ext import commands
trivia_list = {
"Capital of Spain?": "madrid",
"Capital of India?": "delhi",
"Language with the most words?": "english",
"What is the hardest rock?": "diamond",
"Planet with the most gravity?": "jupiter",
"What year was the first iPhone released?": "2007",
"What does DC stand for (the comics)?": "detective comics",
"What country won the very first FIFA World Cup in 1930?": "uruguay",
"What is the body's largest organ?": "skin"
}
economy = {}
def random_trivia(test):
random.choice(list(trivia_list))
client = commands.Bot(command_prefix=">")

@client.command()
async def trivia(ctx, be_am):
global ongt
ongt = True
global user
global be
user = ctx.author
be = int(be_am)
if int(be_am) <= economy[ctx.author]:
await ctx.send(random_tri())
@client.command()
async def ans(ctx, answer):
if not ongt:
await ctx.send("Test")
if ctx.author != user:
return ""
if user in economy:
if be > economy[user]:
await ctx.send("Sorry! You can't bet more than you already have.")
con_ans = answer.lower()
if trivia_list[chosen_trivia] in con_ans:
await ctx.send("Correct!")
if user in economy:
economy[user] += be
else:
economy[user] = be
await ctx.send(f"You now have {economy[user]} coins!")
ongt = False
if trivia_list[chosen_trivia] not in con_ans:
await ctx.send(f"Incorrect! Answer: {trivia_list[random_tri]}")

除了当我输入>ans命令:命令引发异常:UnboundLocalError:在分配之前引用了本地变量"ongt">

您忘记在ans()中将ongt声明为global

最新更新