mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-16 19:11:00 +00:00
✨ Fix: 修复 MessageSegment 在有额外数据时报错 (#1055)
This commit is contained in:
@ -66,7 +66,11 @@ class MessageSegment(abc.ABC, Generic[TM]):
|
||||
return value
|
||||
if not isinstance(value, dict):
|
||||
raise ValueError(f"Expected dict for MessageSegment, got {type(value)}")
|
||||
return cls(**value)
|
||||
if "type" not in value:
|
||||
raise ValueError(
|
||||
f"Expected dict with 'type' for MessageSegment, got {value}"
|
||||
)
|
||||
return cls(type=value["type"], data=value.get("data", {}))
|
||||
|
||||
def get(self, key: str, default: Any = None):
|
||||
return asdict(self).get(key, default)
|
||||
|
Reference in New Issue
Block a user