如何仅在布尔值为true时运行discord.py命令

2024-10-01 02:32:28 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我想为我的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”


Tags: theinsendifrandombeawaitwhat