Skip to content

[Bug] qq_official:无 message_reference 时仍构造 Reply,且引用内容中的图片被拍平成文本 #10840

Open

Description

@setsuna13482

描述

qq_official(QQ 官方机器人 WebSocket)适配器在解析入站消息时有两处问题,都会让「引用消息」相关的插件拿到错误的内容:

  1. 没有 message_reference 也构造 Reply 组件:QQ 在「被动回复」场景会给消息打上 message_type=103 并把上一条消息塞进 msg_elements,但 message_reference 是空的。适配器只看 message_type==103,于是给一条用户只 @ 了机器人、并没有引用任何消息的消息也造出了 Reply,下游插件会误把上一条旧消息当成待核对象。
  2. 引用内容里的图片被拍平成文本:msg_elements[0].content 是 QQ 预渲染的字符串,图片只剩 [附件1] 类型:图片 文件名:xxx.png 尺寸:... URL:https://... 这样的文字,msg_elements[0].attachments 为空,因此引用里的图片无法还原成 Image 组件。

两处都在 astrbot/core/platform/sources/qqofficial/qqofficial_platform_adapter.py 的 _convert_handle_message_event 中(v4.29.3 为 796/830 行,当前 master 为 812/846 行)。

复现步骤

  1. 使用 QQ 官方机器人(WebSocket)适配器,接入一个群
  2. 先让机器人回复一条消息(制造上下文)
  3. 群里只 @ 机器人并发送「地球是平的是真的吗」(不手动引用任何消息)
  4. 观察事件消息链:chain=Reply+At+Plain,message_type=103,message_reference 为空
  5. 使用一个「引用优先」的插件(例如 astrbot_plugin_isittrue),可以看到它把上一条旧消息当成了核查对象

引用一条聊天记录/合并转发消息时,问题 2 同样出现:引用的图片全部变成 [附件N] ... URL:... 文本,插件拿不到图片。

AstrBot 版本

4.29.3

操作系统

Windows

部署方式

Windows 桌面版(AstrBot Launcher)

消息平台适配器

QQ 官方机器人(WebSocket)

错误日志

在插件里打印入站原始载荷与解析结果(关键字段已脱敏):

[是真的吗] 载荷 | message_type=103 reference=no msg_elements=1 chain=Reply+At+Plain
[是真的吗] 提取 | source=引用消息 text_len=735 images=1 supplement_len=6

reference=no 说明 message_reference 为空,但 chain 里仍然有 Reply。

事件 message_str 的渲染结果(用户只 @ 了机器人):

[引用消息(: === 消息 1 ===
[消息类型] 引用消息
[附件1] 类型:图片 文件名:xxxx.png 尺寸:2117x287 大小:57.3KB URL:https://multimedia.nt.qq.com.cn/download?appid=1407&fileid=<redacted>&rkey=<redacted>&spec=0

=== 消息 2 ===
[消息内容] <旧消息文本>
...
)] [At:qq_official] 地球是平的是真的吗

可以看到引用内容整体是一段文本,图片以 [附件1] ... URL: 形式内嵌。

官方机器人与私人 QQ 号(OneBot)的差异

这个差异是问题容易被忽略的原因,供参考:

私人 QQ 号(aiocqhttp / OneBot v11,NapCat、Lagrange 等) QQ 官方机器人(qq_official)
引用消息怎么拿 通过 OneBot get_msg 拉取完整消息链 只能读推送里的 msg_elements[0],没有 call_action
引用里的图片 独立 image 段,带 http url,可正常解析 被拍平成 [附件N] 类型:图片 ... URL:... 文本
怎么判断"有引用" 存在 reply 段 message_type==103 或 message_reference
框架工具函数 extract_quoted_message_images() 可用 该函数依赖 OneBot call_action,恒返回空列表

也就是说:同样的「引用一条带图消息问真假」,在私人 QQ 号下能读到图,在官方机器人下既读不到图,还可能因为 message_type=103 的误判去核查错的对象。

期望行为

  1. 仅在确实存在引用消息 id 时才构造 Reply:

    • message_reference.message_id 存在,或
    • msg_elements[0].id / message_id 存在

    message_type=103 但两者都没有时,应视为被动回复回声,不构造 Reply(或至少不应被下游当作"用户主动引用")。

  2. 解析 msg_elements[0].content 中的 [附件N] ... URL:<url>,把其中的图片还原为 Image 组件(同时优先使用 attachments 字段,若其非空)。

补充

我在本地对第 1 点做了临时验证性修改(仅改 Reply 的构造条件,quoted_chain 有内容但无 id 时跳过并打日志),确认可以消除误判;第 2 点暂未改框架,只在插件侧做了 [附件N] ... URL: 的正则回收作为兜底。如果需要,我可以整理成 PR。

检查清单

  • 我已在 Issue 列表中搜索过相关问题仍无法解决,或该问题从未被报告过
  • 我已尝试过禁用所有插件,排除了可能是因插件导致的问题(该问题在原始消息链层面即可复现,与插件无关)
  • 我报告的问题与 AstrBot 本体相关,而非在报告某一插件的问题
  • 我已阅读并同意本项目的贡献者行为准则
  • (可选) 我愿意提交 PR 以帮助修复该问题

Activity

  1. he-yufeng commented on Oct 29, 2026

    @he-yufeng
    Contributor

    Both parts are covered by #10842, which I opened before seeing this report. The reproduction you describe matches what I hit.

    Part 1, the invented Reply: the adapter treated message_type == 103 as proof that a message quotes something, so a bare mention got a Reply pointing at whatever the previous message happened to be. #10842 keys the quote on message_reference actually carrying content instead, so a passive echo with no reference builds no Reply at all.

    Part 2, quoted images flattened to prose: QQ renders a quoted attachment into the quoted text as [附件N] 类型:图片 ... URL:<url> and leaves attachments empty. #10842 lifts those lines back out of the pre-rendered string and appends a real Image from the URL, so plugins see an image rather than a filename and a URL inside a sentence. Other attachment kinds are deliberately left as text, since the flattened form does not give enough to rebuild them faithfully.

    Both live in _convert_handle_message_event / _parse_from_qqofficial, with coverage in tests/test_qqofficial_group_message_create.py including the no-message_reference case and the flattened-image case.

    Status is honest: #10842 is open, CI is green across the three platforms and CodeQL, and it has not been reviewed or merged yet. If you would rather track the two halves separately, say so and I will split the image half into its own PR.

  2. moved this to In Progress in AstrBot Roadmapon Nov 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions