问题描述
我正在使用 Telethon 构建一个应用程序并且几乎完成了。现在还有一些美丽的东西需要制作,我发现互联网(以及文档)中没有很好的解释如何制作机器人的菜单。
一两年前,我用 TeleBot 构建了另一个机器人,它使用 types.ReplyKeyboardMarkup
为其提供了一个很好的解决方案。我可以看到 Telethon 文档如何提到 ReplyKeyboardMarkup
,但我仍然无法完成我的机器人菜单。
为了清楚起见,我想做的事情是这样的:
解决方法
哦,我发现我使用了错误的 Button 类型(inline
而不是 text
)。工作代码:
from telethon import events,Button
bot = ...
@bot.on(events.NewMessage(pattern='/start'))
async def handle_start_command(event):
markup = event.client.build_reply_markup([
[Button.text('First button')],[Button.text('Second button')]
])
await event.respond("Hello!",buttons=markup)
结果如下:
您可以一起使用 inline
、switch_inline
、url
和 auth
来创建
内嵌按钮(在消息下方)。
您可以使用 text
、request_location
、request_phone
和 request_poll
一起创建回复标记(取代用户键盘)。