Skip to content

Commit

Permalink
🐛 修复尝试发送空消息时的报错
Browse files Browse the repository at this point in the history
  • Loading branch information
CMHopeSunshine committed Nov 12, 2023
1 parent 642d286 commit a97534f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions nonebot/adapters/dodo/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,10 @@ def to_message_body(self) -> Tuple[MessageBody, Optional[str]]:
message_id = ref[-1].data["message_id"]
else:
message_id = None
last_seg = self[-1]
msg = self.exclude("reference")
if not msg:
return TextMessage(content=""), None
last_seg = msg[-1]
if isinstance(
last_seg,
(
Expand All @@ -482,11 +485,11 @@ def to_message_body(self) -> Tuple[MessageBody, Optional[str]]:
),
):
return last_seg.message_body, message_id
if card := (self["card"] or None):
if card := (msg["card"] or None):
return CardMessage(
content=self.extract_text_content() or None, card=card[-1].data["card"]
content=msg.extract_text_content() or None, card=card[-1].data["card"]
), message_id
return TextMessage(content=self.extract_text_content()), message_id
return TextMessage(content=msg.extract_text_content()), message_id

def extract_text_content(self) -> str:
return "".join(
Expand Down

0 comments on commit a97534f

Please sign in to comment.