From a79ae323eec618edf5b6ab7ac0afdf640030117c Mon Sep 17 00:00:00 2001 From: Oscar Date: Mon, 22 Dec 2025 19:48:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(core):=20=E5=A2=9E=E5=8A=A0=E6=8C=87?= =?UTF-8?q?=E4=BB=A4=E8=A7=A3=E6=9E=90=E4=B8=8E=E5=90=8C=E6=AD=A5=E8=BF=87?= =?UTF-8?q?=E7=A8=8B=E4=B8=AD=E7=9A=84=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/star/command_management.py | 18 ++++++++++++------ astrbot/core/star/star_manager.py | 6 +++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/astrbot/core/star/command_management.py b/astrbot/core/star/command_management.py index a0b125d33..190ef2000 100644 --- a/astrbot/core/star/command_management.py +++ b/astrbot/core/star/command_management.py @@ -4,7 +4,7 @@ from dataclasses import dataclass, field from typing import Any -from astrbot.core import db_helper +from astrbot.core import db_helper, logger from astrbot.core.db.po import CommandConfig from astrbot.core.star.filter.command import CommandFilter from astrbot.core.star.filter.command_group import CommandGroupFilter @@ -192,12 +192,18 @@ def _collect_descriptors(include_sub_commands: bool) -> list[CommandDescriptor]: """收集指令,按需包含子指令。""" descriptors: list[CommandDescriptor] = [] for handler in star_handlers_registry: - desc = _build_descriptor(handler) - if not desc: - continue - if not include_sub_commands and desc.is_sub_command: + try: + desc = _build_descriptor(handler) + if not desc: + continue + if not include_sub_commands and desc.is_sub_command: + continue + descriptors.append(desc) + except Exception as e: + logger.warning( + f"解析指令处理函数 {handler.handler_full_name} 失败,跳过该指令。原因: {e!s}" + ) continue - descriptors.append(desc) return descriptors diff --git a/astrbot/core/star/star_manager.py b/astrbot/core/star/star_manager.py index 1f9f95ae5..c142c0e9b 100644 --- a/astrbot/core/star/star_manager.py +++ b/astrbot/core/star/star_manager.py @@ -631,7 +631,11 @@ async def load(self, specified_module_path=None, specified_dir_name=None): # 清除 pip.main 导致的多余的 logging handlers for handler in logging.root.handlers[:]: logging.root.removeHandler(handler) - await sync_command_configs() + try: + await sync_command_configs() + except Exception as e: + logger.error(f"同步指令配置失败: {e!s}") + logger.error(traceback.format_exc()) if not fail_rec: return True, None