From ff0c0992ff8c806135a0faccc5efe5418426041d Mon Sep 17 00:00:00 2001 From: Raven95676 Date: Tue, 25 Mar 2025 14:46:20 +0800 Subject: [PATCH] Improves Telegram adapter termination --- astrbot/core/platform/sources/telegram/tg_adapter.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/astrbot/core/platform/sources/telegram/tg_adapter.py b/astrbot/core/platform/sources/telegram/tg_adapter.py index 77fe3e42b..12f17a819 100644 --- a/astrbot/core/platform/sources/telegram/tg_adapter.py +++ b/astrbot/core/platform/sources/telegram/tg_adapter.py @@ -241,5 +241,13 @@ class TelegramPlatformAdapter(Platform): return self.client async def terminate(self): - await self.application.stop() - logger.info("Telegram 适配器已被优雅地关闭") + try: + await self.application.stop() + + # 保险起见先判断是否存在updater对象 + if self.application.updater is not None: + await self.application.updater.stop() + + logger.info("Telegram 适配器已被优雅地关闭") + except Exception as e: + logger.error(f"Telegram 适配器关闭时出错: {e}")