Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

[Bug] QQ频道消息无法回复:markdown 回退顺序有误,误用主动消息导致 304049 限频

Open Beginner friendly
#10,420 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
api

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

🔁 复现

  1. use_markdown = true
  2. 用户在 QQ 频道给机器人发消息
  3. 机器人回复失败

📜 日志

[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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from AstrBotDevs/AstrBot

All issues in AstrBotDevs/AstrBot

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.