如何在电报Bot中用键盘回复?

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

我有一个电报机器人,应该在/faq命令和每个/faq键盘选项上显示keyboard1以可视化一些文本(文本尚未添加)。>>

这是我正在创建的第一个机器人,并且存在一些问题:

  1. 机器人不会连续收听命令
  2. 它不显示/faq处的keyboard1
  3. 另一个奇怪的事情是,它保留了代码中不再存在的键盘选项,我的意思是我仍然可以看到在先前代码版本中创建的inlinekeyboard,而且我不知道如何摆脱它。有人可以帮忙吗?这是代码:
  4. import telebot
    from tkinter import *
    from telegram.ext import Updater
    from telegram.ext import CommandHandler, CallbackQueryHandler
    from telegram import InlineKeyboardButton, InlineKeyboardMarkup
    
    bot = telebot.TeleBot('TOKEN')
    updater = Updater('TOKEN', use_context=True)
    updater.dispatcher.add_handler(CommandHandler('start', ...))
    
    @bot.message_handler(commands=['help','start'])
    def send_welcome(message):
        if message.text == "/start":
            updater.send_message(message.chat.id,'Some welcome text')
        elif message.text == "/help":
                updater.send_message(message.chat.id,
                                 'list of all commands')
      elif message.text == "/lastin":
                updater.send_message(message.chat.id,
                                 'some text')
    def build_menu(buttons,
                   n_cols,
                   header_buttons=None,
                   footer_buttons=None):
        menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)]
        if header_buttons:
            menu.insert(0, [header_buttons])
        if footer_buttons:
            menu.append([footer_buttons])
        return menu
    
    keyboard1 = [[InlineKeyboardButton('Question 1', callback_data='q1')],
                [InlineKeyboardButton('Question 2', callback_data='q2')],
                [InlineKeyboardButton('Question 3', callback_data='q3')],
                [InlineKeyboardButton('Question 4', callback_data='q4')]]
    reply_markup = InlineKeyboardMarkup(build_menu(keyboard1, n_cols=2))
    
    @bot.message_handler(content_types=['text'])
    def send_text(message):
        if message.text == "/faq":
            bot.send_message(message.chat.id, text = 'FAQ', reply_markup = reply_markup)
        elif message.text == "/lastin":
            bot.send_photo(message.chat.id, photo='https://telegram.org/img/t_logo.png')
    
    
    updater.start_polling()
    

我有一个电报自动程序,应该在/ faq命令和每个/ faq键盘选项上显示keyboard1at以使某些文本可视化(该文本尚未添加)。这是我创建的第一个机器人,...

python python-3.x telegram telegram-bot python-telegram-bot
1个回答
0
投票

您似乎同时使用python-telegram-bottelebot,这可能会引起问题。

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