【发布时间】:2021-11-12 15:26:18
【问题描述】:
问题:当两个或更多用户使用 bot 的 this 功能时 - 假设第一个用户的正确答案是 ex。 30 和第二个用户的正确答案是 10 ,问题是如果第一个用户给出错误的答案,那么函数会生成新的谜题(新数字)并且第一个用户的正确答案也会改变,但我的代码也会改变第二个用户的正确答案。
我正在使用 pyTelegramBotApi (Telebot) python 库
这是我的代码:
n1 = random.randint(1, 100)
n2 = random.randint(1, 100)
# Generating Random Number For Verifications
def genrate_random():
global n1, n2
n1 = random.randint(1, 100)
n2 = random.randint(1, 100)
# Bot Start Command
@bot.message_handler(commands=['start'])
def start_command(message):
genrate_random()
chat_id = message.chat.id
prove_yourself(chat_id)
def prove_yourself(chat_id):
result = bot.send_message(chat_id, "ℹ️ Prove That You Are A Human!\n\n" + str(n1) + '+' + str(n2) + " = ?")
bot.register_next_step_handler(result, verifyUser)
def verifyUser(message):
if int(message.text) != int(n1 + n2):
bot.send_message(message.chat.id, '❌ Wrong Answer ❌')
genrate_random()
prove_yourself(message.chat.id)
else:
print("next step")
【问题讨论】:
-
如果有什么不懂的可以问我
标签: python bots telegram-bot python-telegram-bot py-telegram-bot-api