[Bug]NapCat + aiocqhttp 收到 QQ 视频消息时,AstrBot 将 video.file 解析为无效文件名,导致 Error processing video attachment: not a valid file
What happened / 发生了什么
在使用 NapCat + AstrBot(aiocqhttp / OneBot v11 适配器)时,QQ 用户发送视频消息后,AstrBot 会报错:
[Core][ERRO][v4.24.2] [core.astr_main_agent:655]: Error processing video attachment: not a valid file: 8df7673a71f8540186c33f047b806c57.mp4
日志显示 AstrBot 在处理视频附件时,拿到的是一个类似 8df7673a71f8540186c33f047b806c57.mp4 的文件名,但这并不是容器内真实存在的可访问视频路径,因此 convert_to_file_path() 失败。
Reproduce / 如何复现?
- 使用 NapCat 和 AstrBot,二者部署在同一台服务器的不同 Docker 容器中
- AstrBot 使用
aiocqhttp适配器接收 QQ 消息 - QQ 用户向机器人发送一个视频消息
- AstrBot 日志中出现:
Error processing video attachment: not a valid file: xxx.mp4
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
- 1Panel
- Docker Compose
- NapCat 和 AstrBot 在不同容器中
- 已确认共享挂载已配置
AstrBot 容器挂载了:
/opt/1panel/apps/Astrbot/ntqq -> /app/.config/QQ
/opt/1panel/apps/Astrbot/data -> /AstrBot/data
NapCat 容器也挂载了相同的 ntqq 目录。
AstrBot 版本
- v4.24.2
协议端 / 平台
- NapCat
- aiocqhttp / OneBot v11
- QQ 私聊 / 群聊均可复现(我这里是在个人 QQ 场景下复现)
OS
Windows
Logs / 报错日志
实际排查结果
我已经做过以下排查:
1. 共享挂载没有问题
NapCat 和 AstrBot 都挂载了同一个宿主机目录到 /app/.config/QQ。
2. NapCat 容器里确实存在视频缓存文件
在 NapCat 容器中执行:
find / -name "*.mp4" 2>/dev/null | head -50
可以找到真实视频文件,例如:
/app/.config/QQ/nt_qq_253aed7e0b8a3e5ea712a7ff1a9d2b39/nt_data/Video/2026-04/Ori/32300fb4b6d5801d2d48c0ae99d50a4c.mp4
3. 但是 AstrBot 报错里拿到的并不是这个真实路径
AstrBot 报错里拿到的是:
8df7673a71f8540186c33f047b806c57.mp4
这个值:
- 不是
file:///... - 不是
http(s)://... - 不是容器内真实存在的绝对路径
- 甚至和 NapCat 实际缓存文件名也不一致
4. 代码层面定位结果
在 astrbot/core/message/components.py 中:
class Video(BaseMessageComponent):
async def convert_to_file_path(self) -> str:
url = self.file
if url and url.startswith("file:///"):
return url[8:]
if url and url.startswith("http"):
...
if os.path.exists(url):
return os.path.abspath(url)
raise Exception(f"not a valid file: {url}")
这里 Video.convert_to_file_path() 只支持:
file:///...http(s)://...- 本地存在的路径
因此当 self.file == "8df7673a71f8540186c33f047b806c57.mp4" 时,会必然抛出:
not a valid file: 8df7673a71f8540186c33f047b806c57.mp4
5. aiocqhttp 适配器中,file 类型已有 NapCat 特殊处理,但 video 没有
在 astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py 中:
file类型会单独处理,并调用 NapCat API 获取真实 URL- 但
video类型没有单独分支,而是走了兜底逻辑:
a = ComponentTypes[t](**m["data"])
abm.message.append(a)
这意味着 video 段最终大概率被直接构造成了:
Video(file="8df7673a71f8540186c33f047b806c57.mp4")
随后在 astr_main_agent.py 中调用 video.convert_to_file_path() 时失败。
我怀疑的问题点
怀疑是 aiocqhttp 适配器对 NapCat 的 video 消息段没有做专门兼容:
file类型已有 NapCat 特殊处理video类型缺少类似处理- 导致 OneBot / NapCat 提供的
video.data.file被直接当成本地文件路径使用
建议的修复方向
可能的修复方向:
- 在
aiocqhttp_platform_adapter.py中为video增加专门分支,不走通用兜底 - 如果 NapCat 原始
video段中存在可用 URL / path / file_id,则转换为 AstrBot 可识别的Video(file=...) - 如果需要,可仿照
file类型调用 NapCat API 获取可访问地址 - 或者至少在
video无法解析时不要把无效file直接传入Video
相关代码位置
astrbot/core/message/components.pyastrbot/core/astr_main_agent.pyastrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py
附加日志
[2026-05-06 15:42:49.642] [Core][INFO][core.event_bus:61]: [default] [个人QQ(aiocqhttp)] Sense/307062828: [ComponentType.Video]
[2026-05-06 15:42:49.652] [Core][ERRO][v4.24.2] [core.astr_main_agent:655]: Error processing video attachment: not a valid file: 8df7673a71f8540186c33f047b806c57.mp4
Are you willing to submit a PR? / 你愿意提交 PR 吗?
- [ ] Yes!
Code of Conduct
- [x] I have read and agree to abide by the project's Code of Conduct。
@AmeiMiao 你的分析很到位。这个问题和你之前报告的 #7686 语音消息 bug 本质上是同一类问题 [1]——Record 当时缺少 self.url or self.file 回退逻辑,现在 Video 也是一样的情况。
确认你的定位:
-
video类型在 aiocqhttp 适配器中没有像file类型那样的 NapCat 特殊处理——file会调用 NapCat API(get_group_file_url/get_private_file_url)获取真实 URL,而video直接走通用的ComponentTypes映射,原样构造Video(file="xxx.mp4")[2]。 -
Video.convert_to_file_path()只支持file:///、http(s)://、本地已存在的路径,所以一个裸文件名必然失败 [3]。
修复方向可以双管齐下:
- 在
aiocqhttp_platform_adapter.py中为video段增加 NapCat 分支(类似file的处理,调用 NapCat API 或使用url字段获取可访问地址) - 在
Video.convert_to_file_path()中补充url = self.url or self.file的回退逻辑(与Image保持一致),作为兜底保护
这与 #7686 中 Record 的修复思路完全一致。
To reply, just mention @dosu.
Docs are dead. Just use Dosu.
hi, #8523 has fixed the issue.