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