python-telegram-bot键盘未出现

时间:2019-03-05 08:33:21

标签: python-telegram-bot

我正在尝试制作一个用于频道管理的机器人,但用于频道选择的键盘(代码中的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()

1 个答案:

答案 0 :(得分:0)

replyMarkup替换为reply_markup

enter image description here