[Bug接收消息时,只能接收图片消息,接收文字消息时直接报错
What happened / 发生了什么
在我的服务器中(版本为Windows - Server2022),手动部署或一键部署成功,接入napcat之后,发现日志只能返回图片消息,接收文字消息时直接报错,重装系统后再次部署,仍然报错
Reproduce / 如何复现?
1.安装Python环境 2.下载astrbot一键部署压缩包并正常部署,提示启动成功 3.下载napcat desktop并安装 4.配置平台适配器 5.提示接入成功 6.私聊/群聊发送任意文字消息(我发送的是astrbot内置指令) 7.控制台报错
AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器
4.16.0,Windows源码部署,未使用提供商,napcat desktop
OS
Windows
Logs / 报错日志
[15:26:28] [Core] [INFO] [aiocqhttp.aiocqhttp_platform_adapter:106]: aiocqhttp(OneBot v11) 适配器已连接。 [15:26:58] [Core] [ERRO] [v4.16.0] [aiocqhttp.aiocqhttp_platform_adapter:101]: Handle private message failed: 'Plain' object has no attribute 'text' Traceback (most recent call last): File [35m"D:\000000011111\AstrBot\astrbot\core\platform\sources\aiocqhttp\aiocqhttp_platform_adapter.py"[0m, line [35m99[0m, in [35mprivate[0m await self.handle_msg(abm) File [35m"D:\000000011111\AstrBot\astrbot\core\platform\sources\aiocqhttp\aiocqhttp_platform_adapter.py"[0m, line [35m449[0m, in [35mhandle_msg[0m message_event = AiocqhttpMessageEvent( message_str=message.message_str, ...<3 lines>... bot=self.bot, ) File [35m"D:\000000011111\AstrBot\astrbot\core\platform\sources\aiocqhttp\aiocqhttp_message_event.py"[0m, line [35m30[0m, in [35m__init__[0m [31msuper().__init__[0m[1;31m(message_str, message_obj, platform_meta, session_id)[0m [31m~~~~~~~~~~~~~~~~[0m[1;31m^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^[0m File [35m"D:\000000011111\AstrBot\astrbot\core\platform\astr_message_event.py"[0m, line [35m71[0m, in [35m__init__[0m message_outline=[31mself.get_message_outline[0m[1;31m()[0m, [31m~~~~~~~~~~~~~~~~~~~~~~~~[0m[1;31m^^[0m File [35m"D:\000000011111\AstrBot\astrbot\core\platform\astr_message_event.py"[0m, line [35m162[0m, in [35mget_message_outline[0m return [31mself._outline_chain[0m[1;31m(self.message_obj.message)[0m [31m~~~~~~~~~~~~~~~~~~~[0m[1;31m^^^^^^^^^^^^^^^^^^^^^^^^^^[0m File [35m"D:\000000011111\AstrBot\astrbot\core\platform\astr_message_event.py"[0m, line [35m134[0m, in [35m_outline_chain[0m parts.append([1;31mi.text[0m) [1;31m^^^^^^[0m [1;35mAttributeError[0m: [35m'Plain' object has no attribute 'text'[0m
Are you willing to submit a PR? / 你愿意提交 PR 吗?
- [x] Yes!
Code of Conduct
- [x] I have read and agree to abide by the project's Code of Conduct。
Hi @fengqiXx2! I'm Dosu and I’m helping the AstrBot team.
这个问题可能是 napcat 发送的 OneBot 消息格式导致的。根据代码分析:
根本原因:aiocqhttp 适配器在解析消息时使用动态组件实例化 ComponentTypes[t](**m["data"]),如果 napcat 发送的消息数据中缺少 text 字段,会创建一个没有 text 属性的 Plain 对象,导致后续 _outline_chain 方法访问 i.text 时报错。
临时解决方案:可以修改 astrbot/core/platform/astr_message_event.py 第 134 行:
# 原代码
if isinstance(i, Plain):
parts.append(i.text)
# 修改为
if isinstance(i, Plain):
parts.append(getattr(i, 'text', ''))
建议:
- 检查是否有更新版本(v4.16.1+)已修复此问题
- 查看 napcat 发送的原始消息日志,确认具体是什么消息格式触发了此错误
之前有类似的 PR 修复过 aiocqhttp 适配器的空白 Plain 问题(PR #1112),但可能未覆盖所有 napcat 的边缘情况。你愿意提交 PR 的话,可以在相关位置添加防御性检查。
To reply, just mention @dosu.
Share context across your team and agents. Try Dosu.
根据@dosubot的方法尝试,并没有解决
@fengqiXx2 看一下运行 astrbot 的 python 环境的 pip show pydantic,初步怀疑是 pydantic 版本兼容性导致的问题
@Soulter 返回结果如下 (venv) PS D:\2\AstrBot-master\AstrBot-master> pip show pydantic
Name: pydantic Version: 2.12.5 Summary: Data validation using Python type hints Home-page: https://github.com/pydantic/pydantic Author: Author-email: Samuel Colvin [email protected], Eric Jolibois [email protected], Hasan Ramezani [email protected], Adrian Garcia Badaracco [email protected], Terrence Dorsey [email protected], David Montague [email protected], Serge Matveenko [email protected], Marcelo Trylesinski [email protected], Sydney Runkle [email protected], David Hewitt [email protected], Alex Hall [email protected], Victorien Plot [email protected], Douwe Maan [email protected] License-Expression: MIT Location: D:\2\AstrBot-master\AstrBot-master\venv\Lib\site-packages Requires: annotated-types, pydantic-core, typing-extensions, typing-inspection Required-by: anthropic, google-genai, mcp, openai, pydantic-settings, sqlmodel, xinference-client
我已解决,原因是Python是3.14.3,换回3.12.10完美解决
我看3.14挺多不兼容的,在bilibili的qqbot部署视频下面也有人留言说3.14有bug
我看3.14挺多不兼容的,在bilibili的qqbot部署视频下面也有人留言说3.14有bug
不兼容的基本都是前置库,自己编译就好(但是不是所有人都可以编译别的语言的库
最新的版本已经适配了 3.14.