我如何让电报机器人等待响应?

问题描述 投票:0回答:1

我编写了一个电报机器人,该机器人检查输入的消息的字典键,如果消息与字典值匹配/不匹配,则该机器人将输出消息“ true” /“ not true”,并转到下一个键。但是,当我使用for in循环浏览字典时,该漫游器不会期望响应,而是会立即显示字典中的所有键。

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

我的代码:

@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)
python python-3.x telegram-bot python-telegram-bot
1个回答
0
投票

不理解您的问题

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

您所需要做的就是设置电报机器人并编写函数以执行所需的操作;

阅读此:https://core.telegram.org/bots/api#making-requests

Telegram 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监听传入的请求您可以编写代码以执行所需的操作

希望这会有所帮助

欢呼声

© www.soinside.com 2019 - 2024. All rights reserved.