AstrBot icon indicating copy to clipboard operation
AstrBot copied to clipboard

[Bug接收消息时,只能接收图片消息,接收文字消息时直接报错

Open fengqiXx2 opened this issue 9 months ago • 8 comments

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 "D:\000000011111\AstrBot\astrbot\core\platform\sources\aiocqhttp\aiocqhttp_platform_adapter.py", line 99, in private await self.handle_msg(abm) File "D:\000000011111\AstrBot\astrbot\core\platform\sources\aiocqhttp\aiocqhttp_platform_adapter.py", line 449, in handle_msg message_event = AiocqhttpMessageEvent( message_str=message.message_str, ...<3 lines>... bot=self.bot, ) File "D:\000000011111\AstrBot\astrbot\core\platform\sources\aiocqhttp\aiocqhttp_message_event.py", line 30, in __init__ super().__init__(message_str, message_obj, platform_meta, session_id) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\000000011111\AstrBot\astrbot\core\platform\astr_message_event.py", line 71, in __init__ message_outline=self.get_message_outline(), ~~~~~~~~~~~~~~~~~~~~~~~~^^ File "D:\000000011111\AstrBot\astrbot\core\platform\astr_message_event.py", line 162, in get_message_outline return self._outline_chain(self.message_obj.message) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\000000011111\AstrBot\astrbot\core\platform\astr_message_event.py", line 134, in _outline_chain parts.append(i.text) ^^^^^^ AttributeError: 'Plain' object has no attribute 'text'

Are you willing to submit a PR? / 你愿意提交 PR 吗?

  • [x] Yes!

Code of Conduct

fengqiXx2 avatar Feb 14 '26 07:02 fengqiXx2

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', ''))

建议:

  1. 检查是否有更新版本(v4.16.1+)已修复此问题
  2. 查看 napcat 发送的原始消息日志,确认具体是什么消息格式触发了此错误

之前有类似的 PR 修复过 aiocqhttp 适配器的空白 Plain 问题(PR #1112),但可能未覆盖所有 napcat 的边缘情况。你愿意提交 PR 的话,可以在相关位置添加防御性检查。

To reply, just mention @dosu.


Share context across your team and agents. Try Dosu.

Leave Feedback Learn about AstrBot with Dosu Add Dosu to your team

dosubot[bot] avatar Feb 14 '26 07:02 dosubot[bot]

根据@dosubot的方法尝试,并没有解决

fengqiXx2 avatar Feb 14 '26 10:02 fengqiXx2

@fengqiXx2 看一下运行 astrbot 的 python 环境的 pip show pydantic,初步怀疑是 pydantic 版本兼容性导致的问题

Soulter avatar Feb 15 '26 08:02 Soulter

@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

fengqiXx2 avatar Feb 15 '26 10:02 fengqiXx2

我已解决,原因是Python是3.14.3,换回3.12.10完美解决

fengqiXx2 avatar Feb 15 '26 12:02 fengqiXx2

我看3.14挺多不兼容的,在bilibili的qqbot部署视频下面也有人留言说3.14有bug

NayukiChiba avatar Feb 15 '26 12:02 NayukiChiba

我看3.14挺多不兼容的,在bilibili的qqbot部署视频下面也有人留言说3.14有bug

不兼容的基本都是前置库,自己编译就好(但是不是所有人都可以编译别的语言的库

Sjshi763 avatar Feb 17 '26 16:02 Sjshi763

最新的版本已经适配了 3.14.

Soulter avatar Mar 26 '26 18:03 Soulter