【问题标题】:Repeat action on button click in telebot module对远程机器人模块中的按钮单击重复操作
【发布时间】:2022-08-14 06:52:10
【问题描述】:

我正在用 Python 实现一个简单的函数,但它不起作用

功能:

# Рандомное число с кнопкой
@bot.message_handler(content_types=[\'text\'], commands=[\'get_number\'])
def get_number(message):
    number = random.randint(0, 1000)
    markup = types.InlineKeyboardMarkup()
    item_yes = types.InlineKeyboardButton(\'Да\', callback_data=\'yes\')
    item_no = types.InlineKeyboardButton(\'Нет\', callback_data=\'no\')
    markup.row(item_yes, item_no)
    bot.send_message(message.chat.id, f\"<i><b>Ваше число:</b></i>\\n{number}\\n\\nЗагадать еще раз?\", reply_markup=markup,
                 parse_mode=\'html\')


# Реакция на нажатие кнопки
@bot.callback_query_handler(func=lambda call: True)
def answer(call, message):
    if call.data == \'yes\':
        pass
    elif call.data == \'no\':
        pass

告诉我怎么做,当你点击“是”按钮时,当你再次点击它时,该功能被执行,当你点击“否”时,它相应地停止。

    标签: python telegram telegram-bot


    【解决方案1】:

    我相信你可以改变你的方法:

    def answer(call, message):
    

    为了

    def handle_query(call):
    

    【讨论】:

      猜你喜欢
      • 2013-01-16
      • 1970-01-01
      • 2022-10-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多