【发布时间】:2020-03-01 08:28:04
【问题描述】:
我正在使用 Python Telegram BOT API 来构建演示应用程序。我要完成的任务是创建一个自定义键盘,然后在每次与用户交互时继续编辑键盘键。我尝试使用“edit_message_reply_markup”,但收到错误“无法编辑消息”。不能编辑自定义键盘吗?
这是我为我的任务编写的示例代码。
初始任务:
FirstKeyboard = [[KeyboardButton(text = "FRUITS"), KeyboardButton(text = "VEGITABLES"), KeyboardButton(text = "DRINKS")],[KeyboardButton(text = "SNACKS"), KeyboardButton(text = "CHIPS"), KeyboardButton(text = "NOTHING")],[KeyboardButton(text = "DONE")]]
menu = ReplyKeyboardMarkup(FirstKeyboard)
KeyboardMessageID = context.bot.send_message(chat_id = chatID, text = "Select What you Like", reply_markup = menu)
编辑任务:
SecondKeyBoard = [[KeyboardButton(text = "APPLE"), KeyboardButton(text = "BANANA"), KeyboardButton(text = "PUMPKIN")],[KeyboardButton(text = "ORANGES"), KeyboardButton(text = "GRAPES"), KeyboardButton(text = "WINE")],[KeyboardButton(text = "DONE")]]
menu = ReplyKeyboardMarkup(SecondKeyBoard)
KeyboardMessageID = context.bot.edit_message_reply_markup(chat_id = chatID, message_id = KeyboardMessageID, reply_markup = menu)
我收到错误消息“无法编辑消息”
【问题讨论】:
-
使用 context.message.reply_text("你的文字", reply_markup=你的键盘标记)。并确保至少有一个文本或标记发生了更改,然后您在相同的输入中遇到错误。
标签: telegram telegram-bot python-telegram-bot