#Discord Bot: UnboundLocalError: cannot access local variable 'cur_round' where it is not associated

8 messages · Page 1 of 1 (latest)

modest sluiceBOT
#

@carmine valve

solar_rel Uploaded Some Code

with a value.

I'm making a Discord Bot that plays a game but idk what this means. I already made it a global variable but it didn't resolve the issue.

This is my full code except for the bot token ofc. I'd enjoy tips to optimize it as well.

Uploaded these files to a Gist
cosmic nest
#

Can you give the full error message

#

Is the error on line 104???

carmine valve
#

Traceback (most recent call last):
File "C:\Users[Username]\AppData\Local\Programs\Python\Python311\Lib\site-packages\discord\client.py", line 441, in _run_event
await coro(*args, **kwargs)
File "C:\Users[Username]\Downloads\test.py", line 103, in on_message
UnboundLocalError: cannot access local variable 'cur_round' where it is not associated with a value

cosmic nest
#

Also you need to await cal_score whenever you call it since it's an async function

#

Ok yeah, you're only assigning a value to cur_round inside of the elif but you have an if at the end of your on_message function that is using cur_round so if that elif on line 21 doesn't run you get the error you're getting

carmine valve
#

Okay someone helped me improve my code A LOT but now it doesn't send anything in the chat

modest sluiceBOT
#

@carmine valve

solar_rel Uploaded Some Code
Uploaded these files to a Gist