From 3cc9351c0902f59a2c5385bd3128dd79c93c37ac Mon Sep 17 00:00:00 2001 From: SXP-Simon Date: Sun, 2 Nov 2025 15:40:22 +0800 Subject: [PATCH] =?UTF-8?q?[debug]=20=E5=B0=9D=E8=AF=95=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=86=E6=9E=90=E5=99=A8=E7=9A=84=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=BF=90=E8=A1=8C=E6=97=B6=E9=94=99=E8=AF=AF?= =?UTF-8?q?=EF=BC=9A'Client'=20object=20has=20no=20attribute=20'api'=20?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/message_handler.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/core/message_handler.py b/src/core/message_handler.py index 6c7d8e1..cb24a3c 100644 --- a/src/core/message_handler.py +++ b/src/core/message_handler.py @@ -82,7 +82,24 @@ class MessageHandler: "reverseOrder": True, } - result = await bot_instance.api.call_action("get_group_msg_history", **payloads) + # 诊断日志:检查bot_instance的属性 + logger.debug(f"bot_instance 类型: {type(bot_instance)}") + logger.debug(f"bot_instance 是否有 'api' 属性: {hasattr(bot_instance, 'api')}") + logger.debug(f"bot_instance 是否有 'call_action' 方法: {hasattr(bot_instance, 'call_action')}") + logger.debug(f"bot_instance 的所有属性: {dir(bot_instance)}") + + # 尝试正确的API调用方式 + if hasattr(bot_instance, 'call_action'): + # 直接调用 call_action 方法 + logger.info(f"使用 bot_instance.call_action 方式调用API") + result = await bot_instance.call_action("get_group_msg_history", **payloads) + elif hasattr(bot_instance, 'api') and hasattr(bot_instance.api, 'call_action'): + # 通过 api 属性调用 + logger.info(f"使用 bot_instance.api.call_action 方式调用API") + result = await bot_instance.api.call_action("get_group_msg_history", **payloads) + else: + logger.error(f"无法找到合适的API调用方法") + raise AttributeError("Client对象缺少call_action方法或api.call_action方法") if not result or "messages" not in result: logger.warning(f"群 {group_id} API返回无效结果: {result}")