Reputation: 23
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):
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]}")
Except I keep getting this error when I input the >ans command : Command raised an exception: UnboundLocalError: local variable 'ongt' referenced before assignment
Upvotes: 0
Views: 337