[Bug] QQ频道消息无法回复:markdown 回退顺序有误,误用主动消息导致 304049 限频
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
Research direction
Start at _send_with_markdown_fallback() in the QQ Official platform source file qqofficial_message_event.py; read the except _QQOFFICIAL_SEND_API_ERRORS branch line by line to see that msg_id is popped before markdown is stripped. The fix branches on the 50056 'markdown not allowed' error first — drop markdown, set plain content and adjust msg_type, keeping msg_id — and only falls back to the proactive (msg_id-less) send for other errors. Done looks like a channel reply succeeding as a passive message with no 304049, while single-chat markdown behavior is unchanged.
Written by the indexing model from the issue text.
Description
🐛 问题描述
QQ 频道场景下机器人无法回复消息,报错「主动消息限频」—— 但这只是普通被动回复。
🌍 环境
- AstrBot
4.28.2(4.29.0-beta.1/master/dev同样存在) - 平台:QQ 官方机器人(
qq_official) - 配置:
use_markdown = true
🔁 复现
use_markdown = true- 用户在 QQ 频道给机器人发消息
- 机器人回复失败
📜 日志
[QQOfficial] 回复消息失败: 不允许发送原生 markdown, 尝试使用主动发送接口。
botpy.errors.NotFoundError: 私信主动消息数限频
https://api.sgroup.qq.com/dms/{guild_id}/messages → 404
🔑 错误码
| 错误码 | 含义 |
|---|---|
50056 |
不允许发送 markdown content(触发点) |
304049 |
私信主动消息数限频(最终失败) |
🔍 根因
qqofficial_message_event.py 的 _send_with_markdown_fallback():
except _QQOFFICIAL_SEND_API_ERRORS as err:
if payload.get("msg_id"):
fallback_payload = payload.copy()
fallback_payload.pop("msg_id", None) # ❌ 先去 msg_id → 变主动消息
return await send_func(fallback_payload) # → 撞 304049
...
# 去掉 markdown、保留 msg_id(正确做法,但轮不到执行)
回退没按错误类型分流:markdown 被拒(50056)时应保留 msg_id、只去掉 markdown。
而官方规定「私信每个用户每天仅 2 条主动消息」,额度一空频道就彻底无法回复。
🛠 建议修复
在去掉 msg_id 之前先处理 markdown:
if (QQOfficialMessageEvent.MARKDOWN_NOT_ALLOWED_ERROR in str(err)
and payload.get("markdown") and plain_text):
md_payload = payload.copy()
md_payload.pop("markdown", None)
md_payload["content"] = plain_text
if md_payload.get("msg_type") == 2:
md_payload["msg_type"] = 0
try:
return await send_func(md_payload) # 保留 msg_id,走被动通道
except _QQOFFICIAL_SEND_API_ERRORS as e2:
err, payload = e2, md_payload
✔️ 验证情况(已实测通过 ✅)
实测方式:临时禁用所有插件层规避手段(即让 markdown 真正被发送),
完整触发 50056 → 回退 链路,观察补丁行为。
实测日志(20:01):
[20:01:34] 频道用户发送消息
[20:01:38] [QQOfficial] 回复消息失败: 不允许发送原生 markdown, 尝试使用主动发送接口。
[20:01:39] [QQOfficial] markdown 不被支持,已改用纯文本(保留被动回复)。 ← 补丁生效
[20:01:39] → 消息发送成功(无 Failed to send)
结果:
- ✅ 频道私信回复恢复正常
- ✅ 回退逻辑按预期执行:保留
msg_id、仅去掉markdown(走被动通道) - ✅ 不再出现
304049 私信主动消息数限频 - ✅ 单聊 markdown 不受影响(`)频道才降级)**
其他已验证项:
- ✅ 根因判断:逐行核对
_send_with_markdown_fallback控制流 - ✅ 补丁可应用性:
patch -p1成功,结果与修复后文件逐字节一致 - ✅ 补丁语法:
py_compile通过
- Dominant language
- Python
- Stars
- 41.4k
- Forks
- 3k
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 140
Getting set up
- Ships a Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from AstrBotDevs/AstrBot
-
Text-to-image rendering suppresses asyncio task cancellationPossibly taken @kilisamemarisaaa claimed this 2 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
AstrBotDevs/AstrBot#10389 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
AstrBotDevs/AstrBot#10388 · 1 comment ·
Maintainers usually reply within 1 day
-
Boxlite boot treats any HTTP response as a healthy sandboxPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
AstrBotDevs/AstrBot#10385 · 2 comments ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
AstrBotDevs/AstrBot#10378 · 1 comment ·
Maintainers usually reply within 1 day
-
[Feature] 移除「切换到旧版知识库」入口Possibly taken @silvaling claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
AstrBotDevs/AstrBot#10340 · 1 reaction ·
Maintainers usually reply within 1 day
All issues in AstrBotDevs/AstrBot
Similar issues
-
area/install reliability
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
FluidNumerics/fluid-walk-blocker#191 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
TransformerLensOrg/TransformerLens#1868 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
climate-analytics-lab/jax-gcm#1057 ·
Maintainers usually reply within 1 day