如何使用pytelegrambotapi创建嵌套菜单?

发布于 2025-02-07 09:00:37 字数 351 浏览 3 评论 0原文

我正在使用pytelegrambotapi创建自己的电报机器人。我想知道如何使用内联按钮创建嵌套菜单。这是我要创建的好示例,这是botfather,bot,它使您可以为机器人创建令牌。如您所见,您仅在一个“消息”中工作,因为这是菜单。

那么,您能为我提供该菜单的最小工作示例吗?提前致谢!

I am creating my own telegram bot with pyTelegramBotAPI. And I wonder how to create nested menu with inline buttons. Here is good example of what I want to create, this is BotFather, bot, that allows you to create tokes for your bots. As you can see, you work in only one "message", because this is menu.

enter image description here

So, could you please provide me a minimal working example of that menu? Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧故 2025-02-14 09:00:37

可以使用edit_message_text方法来完成。这是示例:

...
keyboard = [[types.InlineKeyboardButton("< Go back", callback_data='smt')]]
markup = types.InlineKeyboardMarkup(keyboard)
...
@bot.callback_query_handler(func=lambda call: True)
def commandshandlebtn(call):
    userMessage = call.data
    if userMessage == "smt":
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Some text, for example')

It could be done with edit_message_text method. Here is example:

...
keyboard = [[types.InlineKeyboardButton("< Go back", callback_data='smt')]]
markup = types.InlineKeyboardMarkup(keyboard)
...
@bot.callback_query_handler(func=lambda call: True)
def commandshandlebtn(call):
    userMessage = call.data
    if userMessage == "smt":
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='Some text, for example')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文