|
4 | 4 |
|
5 | 5 | from aiocqhttp import CQHttp, Event |
6 | 6 |
|
| 7 | +from astrbot.api import logger |
7 | 8 | from astrbot.api.event import AstrMessageEvent, MessageChain |
8 | 9 | from astrbot.api.message_components import ( |
9 | 10 | At, |
@@ -156,8 +157,29 @@ async def send_message( |
156 | 157 | payload["user_id"] = session_id |
157 | 158 | await bot.call_action("send_private_forward_msg", **payload) |
158 | 159 | 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 | + ) |
161 | 183 | else: |
162 | 184 | messages = await cls._parse_onebot_json(MessageChain([seg])) |
163 | 185 | if not messages: |
|
0 commit comments