How to only run command if boolean is true

So I'm trying to make a trivia command for my discord bot. I want to make it so when you input the answer you can't not answer once more. I tried something like this:

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):
client = commands.Bot(command_prefix=">")

async def trivia(ctx, be_am):
  global ongt
  ongt = True
  global user
  global be
  user =
  be = int(be_am)
  if int(be_am) <= economy[]:
    await ctx.send(random_tri())

async def ans(ctx, answer):
  if not ongt:
    await ctx.send("Test")
  if != 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
      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]}")

Except I keep getting this error when I input the >ans command : Command raised an exception: UnboundLocalError: local variable 'ongt' referenced before assignment

Read more here:

Content Attribution

This content was originally published by Shlok Sharma at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: