gpt4 book ai didi

telegram - Python Telegram Bot 编辑自定义键盘

转载 作者:行者123 更新时间:2023-12-04 11:02:37 33 4
gpt4 key购买 nike

我正在使用 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)

我收到错误“消息无法编辑”

最佳答案

您可以使用新的 KeyboardButton 发送新消息,而不是编辑以前的消息。新的 ReplyKeyboardMarkup 将自动替换为旧的 ReplyKeyboardMarkup。
使用:

context.bot.send_message(chat_id = chatID, text = "Select What you 
Like", reply_markup = NEW_Menu)

或回复您的用户:
update.message.reply_text(text = "Select What you Like", reply_markup = NEW_Menu)

您可以更改新按摩中的文字或将其作为上一个。

关于telegram - Python Telegram Bot 编辑自定义键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58703309/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com