【问题标题】:how to create new inlinekeyboard when i click old inlinebutton, not replacing当我单击旧的内联按钮时如何创建新的内联键盘,而不是替换
【发布时间】:2019-02-26 07:33:08
【问题描述】:

我是 python-telegram bot 的新手,当我按下旧的内联键盘而不替换旧键盘时,我想创建一个新的内联键盘。 我使用“editMessageText”来处理回调查询。但它只用“reply_markup”替换了内联键盘,但我想创建一个新的内联键盘。 如何解决这个问题呢?我在堆栈溢出中搜索了很多次。但是我现在仍然找不到解决方案? 请帮我解决问题!.我的形象是

这是我的开始(CommandHandler)

def start(bot, update):
    bot.sendChatAction(update.message.chat_id, action=ChatAction.TYPING)
    bot.send_message(chat_id=update.message.chat_id, text=Message.CLAIM,parse_mode='html')
    reply_markup = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton("Check New Model",callback_data="New Model")],
                                                [telegram.InlineKeyboardButton("Reasses my Insurance",callback_data="Reasses")],
                                                [telegram.InlineKeyboardButton("File a Claim",callback_data="claim")]])

    bot.sendMessage(chat_id=update.message.chat_id, text="Choose the above one?", reply_markup=reply_markup)

这是我的回调处理程序

def callback(bot,update):
   query=update.callback_query
   if query.data=="claim":


       reply_markup = telegram.InlineKeyboardMarkup([[telegram.InlineKeyboardButton("Vehicle",callback_data="vehicle")],
                                                    [telegram.InlineKeyboardButton("Personal Accident",callback_data="accident")],
                                                    [telegram.InlineKeyboardButton("Other",callback_data="other")]])
       bot.editMessageText(
                message_id = update.callback_query.message.message_id,
                chat_id = update.callback_query.message.chat.id,
                text = "Choose the one below",
                reply_markup=reply_markup
                )

【问题讨论】:

    标签: python-3.x python-telegram-bot


    【解决方案1】:

    顾名思义,bot.edit_message_text 用于编辑消息的文本。您需要使用bot.edit_message_reply_markup (docs)。

    如果您想在现有键盘上添加一些按钮(如果我理解您的问题),只需将其包含在编辑中:

    reply_markup = telegram.InlineKeyboardMarkup([
    [telegram.InlineKeyboardButton("Check New Model",callback_data="New Model")],
    [telegram.InlineKeyboardButton("Reasses my Insurance",callback_data="Reasses")],
    [telegram.InlineKeyboardButton("File a Claim",callback_data="claim")],[telegram.InlineKeyboardButton("Vehicle",callback_data="vehicle")],[telegram.InlineKeyboardButton("Personal Accident",callback_data="accident")],
    [telegram.InlineKeyboardButton("Other",callback_data="other")]
    ])
    

    【讨论】:

      猜你喜欢
      • 2020-09-06
      • 1970-01-01
      • 2018-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-03
      • 2020-11-02
      相关资源
      最近更新 更多