python-telegram-bot键盘没有出现

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

我正在尝试制作用于频道管理的机器人,并且不会出现用于频道选择的键盘(代码中的channel_markup)。现在这个键盘是硬编码的,但后来我想为通道引入一个基于二手的键盘。

    from telegram import ReplyKeyboardMarkup
    from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, RegexHandler, ConversationHandler)
    from Post import Post

   MENU, CHANNEL = range(2)

   menu_markup = ReplyKeyboardMarkup([['POST', 'HTML']], one_time_keyboard=True, resize_keyboard=True)

   def error(update, context):
       """Log Errors caused by Updates."""
       logger.warning('Update "%s" caused error "%s"', update, error)


   def start(bot, update, user_data):
       reply_text = 'Hi!'
       update.message.reply_text(reply_text, reply_markup=menu_markup)
       return MENU


   def new_post(bot, update, user_data):
       user_data['post'] = Post()
       channel_markup = ReplyKeyboardMarkup([['Test1', 'Test2']], 
                 one_time_keyboard=True, resize_keyboard=True)
       update.message.reply_text(text="Select channel", 
       replyMarkup=channel_markup)
       return CHANNEL


   def channel_choice(bot, update, user_data):
       channel = update.message.text
       user_data['post'].channel = channel
       update.message.reply_text('Hi', reply_markup=menu_markup)
       return MENU


   def test_bot(args):
       pass


   def main():
       updater = Updater("TOKEN")
       dp = updater.dispatcher
       conv_handler = ConversationHandler(

           entry_points=[CommandHandler('start', start, pass_user_data=True)],

           states={
               MENU: [RegexHandler('^POST$', new_post, pass_user_data=True)],

               CHANNEL: [RegexHandler('^Test1$', channel_choice, pass_user_data=True)]
           },

           fallbacks=[RegexHandler('^fallbacks$', test_bot)])

       dp.add_handler(conv_handler)

       # log all errors
       dp.add_error_handler(error)

       # Start the Bot
       updater.start_polling()

       # Run the bot until you press Ctrl-C or the process receives SIGINT,
       # SIGTERM or SIGABRT. This should be used most of the time, since
       # start_polling() is non-blocking and will stop the bot gracefully.
       updater.idle()

python-telegram-bot
1个回答
0
投票

replyMarkup替换reply_markup

enter image description here

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