From f33d31f5fc75e5c0fc9077840ef54ac6c585da10 Mon Sep 17 00:00:00 2001 From: K2cr2O1 <2221577113@qq.com> Date: Tue, 6 Jan 2026 23:52:47 +0800 Subject: [PATCH] 1111 --- core/api/group.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/core/api/group.py b/core/api/group.py index acdb5c6..b2ffb71 100644 --- a/core/api/group.py +++ b/core/api/group.py @@ -199,19 +199,21 @@ class GroupAPI(BaseAPI): # 增加日志记录 API 原始返回 logger.debug(f"OneBot API 'get_group_list' raw response: {res}") - # 健壮性处理:如果返回的是字符串,尝试解析为 JSON - if isinstance(res, str): - try: - res = json.loads(res) - except json.JSONDecodeError: - logger.error(f"Failed to decode JSON from 'get_group_list' response: {res}") + # 健壮性处理:处理标准的 OneBot v11 响应格式 + if isinstance(res, dict) and res.get("status") == "ok": + group_data = res.get("data", []) + if isinstance(group_data, list): + return [GroupInfo(**item) for item in group_data] + else: + logger.error(f"The 'data' field in 'get_group_list' response is not a list: {group_data}") return [] + + # 兼容处理:如果返回的是列表(非标准但可能存在) + if isinstance(res, list): + return [GroupInfo(**item) for item in res] - if not isinstance(res, list): - logger.error(f"Expected a list from 'get_group_list', but got {type(res)}: {res}") - return [] - - return [GroupInfo(**item) for item in res] + logger.error(f"Unexpected response format from 'get_group_list': {res}") + return [] async def get_group_member_info(self, group_id: int, user_id: int, no_cache: bool = False) -> GroupMemberInfo: """