You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Pyrogram用户机器人无法发送Inline Keyboard问题求助

问题分析与解决方案

核心原因:个人账号(Userbot)不支持发送Inline Keyboard

Telegram平台限制**仅机器人账号(通过@BotFather创建、使用bot token登录)**可以发送带有Inline Keyboard的消息。如果你的"用户机器人"是使用个人账号的session文件登录的(即模拟个人账号的bot),即使代码逻辑正确,发送的消息也不会显示Inline Keyboard,且不会触发报错——这是Telegram的规则限制,和代码无关。

排查与解决步骤

  1. 确认账号类型

    • 若当前使用个人账号session登录:
      • 必须改用@BotFather创建的机器人账号,使用对应的bot token初始化Pyrogram Client,才能发送带Inline Keyboard的消息。
    • 若已使用bot token登录:
      • 检查目标聊天ID是否正确:收藏列表(Saved Messages)的chat_id可使用"me"或你自己的用户ID(正数),确认cfg.technical_channel的取值无误。
      • 升级Pyrogram到最新版本:
        pip install --upgrade pyrogram tgcrypto
        
      • 测试发送到普通私人聊天或群组:验证Inline Keyboard是否能正常显示,排除目标聊天的特殊性问题。
  2. 代码验证
    你的发送消息代码逻辑本身无语法错误,可简化为以下形式测试:

    @Client.on_message(filters.chat(cfg.donor_list))
    async def handler1(client: Client, event: Message):
        # 直接构建键盘并发送
        reply_markup = InlineKeyboardMarkup(
            [[InlineKeyboardButton(text='buttontext', callback_data='btn1')]]
        )
        await client.send_message(
            chat_id=cfg.technical_channel,
            text='Message',
            reply_markup=reply_markup
        )
    

补充说明

如果业务必须使用个人账号操作,那么无法实现发送Inline Keyboard的需求——这是Telegram的平台限制,没有绕过方法。只能改用机器人账号完成带键盘的消息发送。

内容的提问来源于stack exchange,提问作者Lil dokie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.05 05:58:18