0

i was creating my own discord bot and for some reason i allways sent me output when i ran my command

local variable referenced 'thing' before assignment

and in these lines of code it told me that 'thing' is not defined

options = starter_thing
    if thing in db.keys():
      options = options + db["thing"]

and

def update_thing(thing_message):
    if thing in db.keys():
        thing = db["thing"]
        thing.append(thing_message)
        db["thing"] = thing
    else:
        db["thing"] = [thing_message
hallo
  • 1

2 Answers2

3

the key is a string:

if "thing" in db.keys():
    ...

or assign a value to the variable thing first:

thing = "thing"
if thing in db.keys():
    ...
examiner
  • 156
  • 6
0

From what I can tell in thhose code snippets, the 'thing' variable does not exist anywhere, so Python doesn't know what you mean when you use 'thing'

Try assigning something to 'thing' like thing = "thingToCheck"

yzAlvin
  • 36
  • 2