Skip to content

Commit 9c7c0ec

Browse files
Merge pull request #6404 from rin259/feat/onebot-file-send
feat: add OneBot V11 file API support for sending files
2 parents 2685528 + 7cce05c commit 9c7c0ec

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

astrbot/core/platform/sources/aiocqhttp/aiocqhttp_message_event.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from aiocqhttp import CQHttp, Event
66

7+
from astrbot.api import logger
78
from astrbot.api.event import AstrMessageEvent, MessageChain
89
from astrbot.api.message_components import (
910
At,
@@ -156,8 +157,29 @@ async def send_message(
156157
payload["user_id"] = session_id
157158
await bot.call_action("send_private_forward_msg", **payload)
158159
elif isinstance(seg, File):
159-
d = await cls._from_segment_to_dict(seg)
160-
await cls._dispatch_send(bot, event, is_group, session_id, [d])
160+
# 使用 OneBot V11 文件 API 发送文件
161+
file_path = seg.file_ or seg.url
162+
if not file_path:
163+
logger.warning("无法发送文件:文件路径或 URL 为空。")
164+
continue
165+
166+
file_name = seg.name or "file"
167+
session_id_int = (
168+
int(session_id) if session_id and session_id.isdigit() else None
169+
)
170+
171+
if session_id_int is None:
172+
logger.warning(f"无法发送文件:无效的 session_id: {session_id}")
173+
continue
174+
175+
if is_group:
176+
await bot.send_group_file(
177+
group_id=session_id_int, file=file_path, name=file_name
178+
)
179+
else:
180+
await bot.send_private_file(
181+
user_id=session_id_int, file=file_path, name=file_name
182+
)
161183
else:
162184
messages = await cls._parse_onebot_json(MessageChain([seg]))
163185
if not messages:

0 commit comments

Comments
 (0)