diff --git a/nonebot/plugin/__init__.py b/nonebot/plugin/__init__.py index 425590d4..f4457d5c 100644 --- a/nonebot/plugin/__init__.py +++ b/nonebot/plugin/__init__.py @@ -7,7 +7,6 @@ import re import json from types import ModuleType -from functools import reduce from dataclasses import dataclass from collections import defaultdict from contextvars import Context, copy_context diff --git a/nonebot/plugin/manager.py b/nonebot/plugin/manager.py index 2cb97d79..b317da97 100644 --- a/nonebot/plugin/manager.py +++ b/nonebot/plugin/manager.py @@ -89,8 +89,20 @@ class PluginManager: if hasattr(_internal_space, internal_id): raise RuntimeError("Plugin manager already exists!") - prefix = sys._getframe(3).f_globals.get( - "__name__") or _internal_space.__name__ + index = 2 + prefix: str = _internal_space.__name__ + while True: + try: + frame = sys._getframe(index) + except ValueError: + break + # check if is called in plugin + if "__plugin_name__" not in frame.f_globals: + index += 1 + continue + prefix = frame.f_globals.get("__name__", _internal_space.__name__) + break + if not prefix.startswith(_internal_space.__name__): prefix = _internal_space.__name__ module = _InternalModule(prefix, self)