我有一个电报机器人,该机器人应该在/faq
命令和每个/faq
键盘选项上显示keyboard1以可视化一些文本(文本尚未添加)。
这是我创建的第一个机器人,并且存在一些问题:
/faq
上没有显示keyboard1 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()
答案 0 :(得分:0)
您似乎同时使用python-telegram-bot和telebot,这可能会引起问题。
由于telebot
似乎还不支持您正在使用的所有功能(例如send_photo),因此您可能要考虑专门使用python-telegram-bot
。