fix(onebot): skip unusable reply segments

Keep delivering valid message content when a reply target cannot be resolved, while retaining strict validation for all other segments.

Fixes #339
This commit is contained in:
DrSmoothl committed 2026-08-09 17:25:48 +08:00
1 parent dbf654ad57
commit 129b091081
4 files changed
+40 -21

No files matched your search

+5
View File
@@ -396,6 +396,11 @@ export async function segmentToElement(type: string, data: Record<string, unknow
if (codec?.fromSegment) {
const element = await codec.fromSegment(data, options);
if (!element) {
// A reply decorates another sendable segment. NapCat-compatible clients
// treat an unusable reply target as best-effort and still deliver the
// remaining content; a reply-only message is rejected by parseMessage's
// final non-empty check below.
if (normalizedType === 'reply') return null;
throw new MessageElementValidationError(
'MISSING_FIELD',
`message segment "${normalizedType}" is missing required or usable fields`,