【问题标题】:Adding an inline keyboard after editing message编辑消息后添加内联键盘
【发布时间】:2018-01-10 18:49:58
【问题描述】:

我有这段代码用于编辑 Telegram 上的消息的按钮。

def startbutton(bot, update):   
    query = update.callback_query        
    toss_keyboard = [[  InlineKeyboardButton("1", callback_data='1'),
                        InlineKeyboardButton("2", callback_data='2'),
                        InlineKeyboardButton("3", callback_data='3'),
                        InlineKeyboardButton("4", callback_data='4'),
                        InlineKeyboardButton("5", callback_data='5'),
                        InlineKeyboardButton("6", callback_data='6')
                    ]]

    toss_markup = InlineKeyboardMarkup(toss_keyboard)
    bot.edit_message_text(text="Click on any of the buttons below:", chat_id=None,message_id=None, inline_message_id = query.inline_message_id)

消息编辑得很好,但我想在 SAME 消息中编辑消息后添加上面的 toss_keyboard(6 个按钮)。我该怎么做?

【问题讨论】:

    标签: python-2.7 telegram-bot python-telegram-bot


    【解决方案1】:

    只需将reply_markup=toss_keyboard 添加到edit_message_text。前面的答案是错误的。 edit_message_text 可以在一次通话中编辑文本和回复标记,而 edit_reply_markup 只能编辑键盘。

    顺便说一句,您可以使用此快捷方式来减少编辑调用中的冗余信息:query.message.edit_text("new text", reply_markup=some_new_markup)

    【讨论】:

      【解决方案2】:

      您可以在documentation 找到,您可以一次编辑消息文本、消息标题或回复标记。由于您的消息没有内嵌键盘,因此您无法在编辑时添加它(没有键盘 -> 无法编辑 nothing,希望你能理解我)。因此,您必须先创建键盘,然后才能对其进行编辑。

      【讨论】:

        猜你喜欢
        • 2019-06-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-03-27
        • 1970-01-01
        • 2020-01-05
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多