Skip to content

[Bug] 发不出 Json 消息 #5198

@pizeroLOL

Description

@pizeroLOL

What happened / 发生了什么

_component_validators = {
Comp.Plain: lambda comp: bool(
comp.text and comp.text.strip(),
), # 纯文本消息需要strip
Comp.Face: lambda comp: comp.id is not None, # QQ表情
Comp.Record: lambda comp: bool(comp.file), # 语音
Comp.Video: lambda comp: bool(comp.file), # 视频
Comp.At: lambda comp: bool(comp.qq) or bool(comp.name), # @
Comp.Image: lambda comp: bool(comp.file), # 图片
Comp.Reply: lambda comp: bool(comp.id) and comp.sender_id is not None, # 回复
Comp.Poke: lambda comp: comp.id != 0 and comp.qq != 0, # 戳一戳
Comp.Node: lambda comp: bool(comp.content), # 转发节点
Comp.Nodes: lambda comp: bool(comp.nodes), # 多个转发节点
Comp.File: lambda comp: bool(comp.file_ or comp.url),
Comp.WechatEmoji: lambda comp: comp.md5 is not None, # 微信表情
}

如上字典里没有 Comp.Json

async def _is_empty_message_chain(self, chain: list[BaseMessageComponent]) -> bool:
"""检查消息链是否为空
Args:
chain (list[BaseMessageComponent]): 包含消息对象的列表
"""
if not chain:
return True
for comp in chain:
comp_type = type(comp)
# 检查组件类型是否在字典中
if comp_type in self._component_validators:
if self._component_validators[comp_type](comp):
return False
# 如果所有组件都为空
return True

并且检查函数为白名单

Reproduce / 如何复现?

随便发一个 json 消息

AstrBot version, deployment method (e.g., Windows Docker Desktop deployment), provider used, and messaging platform used. / AstrBot 版本、部署方式(如 Windows Docker Desktop 部署)、使用的提供商、使用的消息平台适配器

master 分支

OS

Not sure

Logs / 报错日志

[17:45:18.441] [Core] [INFO] [respond.stage:170]: Prepare to send -/: [ComponentType.Json]
[17:45:18.441] [Core] [INFO] [respond.stage:201]: 消息为空,跳过发送阶段
[17:45:18.443] [Core] [INFO] [core.astr_main_agent:932]: 未找到任何对话模型(提供商),跳过 LLM 请求处理。

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

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreThe bug / feature is about astrbot's core, backendbugSomething isn't workingpriority: p0will fix asap

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions