【问题标题】:python-telegram-bot keyboard doesn't appearpython-telegram-bot 键盘没有出现
【发布时间】:2019-03-05 08:33:20
【问题描述】:

我正在尝试制作一个用于频道管理的机器人,但没有出现用于频道选择的键盘(代码中的 channel_markup)。现在这个键盘是硬编码的,但稍后我想介绍一个用于通道的基于使用的键盘。

从电报导入ReplyKeyboardMarkup 从 telegram.ext 导入(Updater、CommandHandler、MessageHandler、Filters、RegexHandler、ConversationHandler) 来自 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】:

    replyMarkup 替换为reply_markup

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-01
      • 2017-07-22
      • 2020-06-10
      • 2015-09-14
      • 2016-04-26
      • 2017-06-18
      相关资源
      最近更新 更多