我如何让电报机器人等待回复



我编写了一个电报bot,它将字典键与输入的消息进行检查,如果消息与字典值匹配/不匹配,bot将输出消息"true"/"not true",并继续下一个键。但是,当我在循环中使用for遍历字典时,机器人并不期望得到响应,而是同时显示字典中的所有键。

我如何让机器人等待字典中每个键的消息?

我的代码:

@bot.message_handler(commands=['help', 'start'])
def newfunc(message):
for key in dict.keys():
bot.reply_to(message, key)
bot.register_next_step_handler(message, func)
def func(message):
rightanswer = 0
wronganswer = 0
for value in dict.values():
if (message.text == value):
bot.send_message(message.chat.id, 'Yes')
rightanswer += 1
else:
bot.send_message(message.chat.id, 'No')
wronganswer += 1
bot.send_message(message.chat.id,'Right answers: {} Wrong answers: {}'.format(rightanswer, wronganswer))

bot.polling(none_stop=True)

不理解您的问题

你可以完全控制机器人的工作方式;

你所需要的只是设置Telegram Bot并编写功能来执行所需的操作;

请阅读以下内容:https://core.telegram.org/bots/api#making-请求

电报Bot API

The Bot API is an HTTP-based interface created for developers keen on building bots for Telegram.
To learn how to create and set up a bot, please consult our Introduction to Bots and Bot FAQ.

有一个具有以下方法的Web应用程序

function doPost(e) {

通过Bot侦听传入请求您可以编写代码来执行所需的操作

希望这能帮助

欢呼

最新更新