#python #asynchronous #global-variables #discord
#python #асинхронный #глобальные переменные #Discord
Вопрос:
Последние несколько дней я разрабатывал бота Discord. Все было хорошо, пока я не столкнулся с этой проблемой:
said_yes = False
said_no = False
@discordclient.event
async def on_ready():
. . .
@discordclient.event
async def on_message(message):
if message.content == '.blackjack':
. . .
if message.content.lower() == 'yes' and said_no == False:
said_yes = True;
. . .
elif message.content.lower() == 'no' and said_yes == False:
said_no = True;
. . .
elif message.content.lower() != '.blackjack' and said_yes == False and said_no == False:
. . .
Сообщение об ошибке:
File "filename.py", line 95, in on_message
elif message.content.lower() == 'no' and said_yes == False:
UnboundLocalError: local variable 'said_yes' referenced before assignment
Эта ошибка возникает во втором if
операторе, а также в первом И втором elif
операторах. Единственная разница заключается в переменной ( said_yes
или said_no
).
Как я могу исправить эту ошибку? Я ожидал, что переменные said_yes
и said_no
будут находиться в глобальной области видимости.