From 9443953c946d4622506b40f1facdd86a48366e23 Mon Sep 17 00:00:00 2001 From: SXP-Simon Date: Mon, 15 Sep 2025 22:17:16 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E5=B0=86=20AutoScheduler=20=E4=B8=AD?= =?UTF-8?q?=E6=AE=8B=E7=95=99=E7=9A=84=20self.bot=5Finstance=20=E5=85=A8?= =?UTF-8?q?=E9=83=A8=E6=94=B9=E4=B8=BA=E9=80=9A=E8=BF=87=20BotManager=20?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E5=AE=9E=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 报错 “‘AutoScheduler’ object has no attribute ‘bot_instance’” 的原因是:我们在解耦后移除了 AutoScheduler 上的 bot_instance 成员,但 AutoScheduler 中发送消息的方法仍然使用了 self.bot_instance。 --- src/scheduler/auto_scheduler.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/scheduler/auto_scheduler.py b/src/scheduler/auto_scheduler.py index c8fd2ee..b06d7b4 100644 --- a/src/scheduler/auto_scheduler.py +++ b/src/scheduler/auto_scheduler.py @@ -216,12 +216,13 @@ class AutoScheduler: async def _send_image_message(self, group_id: str, image_url: str): """发送图片消息到群""" try: - if not self.bot_instance: + bot_instance = self.bot_manager.get_bot_instance() + if not bot_instance: logger.error(f"群 {group_id} 发送图片失败:缺少bot实例") return # 发送图片消息到群 - await self.bot_instance.api.call_action( + await bot_instance.api.call_action( "send_group_msg", group_id=group_id, message=[{ @@ -240,12 +241,13 @@ class AutoScheduler: async def _send_text_message(self, group_id: str, text_content: str): """发送文本消息到群""" try: - if not self.bot_instance: + bot_instance = self.bot_manager.get_bot_instance() + if not bot_instance: logger.error(f"群 {group_id} 发送文本失败:缺少bot实例") return # 发送文本消息到群 - await self.bot_instance.api.call_action( + await bot_instance.api.call_action( "send_group_msg", group_id=group_id, message=text_content @@ -258,12 +260,13 @@ class AutoScheduler: async def _send_pdf_file(self, group_id: str, pdf_path: str): """发送PDF文件到群""" try: - if not self.bot_instance: + bot_instance = self.bot_manager.get_bot_instance() + if not bot_instance: logger.error(f"群 {group_id} 发送PDF失败:缺少bot实例") return # 发送PDF文件到群 - await self.bot_instance.api.call_action( + await bot_instance.api.call_action( "send_group_msg", group_id=group_id, message=[{ @@ -280,7 +283,7 @@ class AutoScheduler: logger.error(f"发送PDF文件到群 {group_id} 失败: {e}") # 发送失败提示 try: - await self.bot_instance.api.call_action( + await bot_instance.api.call_action( "send_group_msg", group_id=group_id, message=f"📊 每日群聊分析报告已生成,但发送PDF文件失败。PDF文件路径:{pdf_path}"