diff --git a/nonebot/__init__.py b/nonebot/__init__.py index a796b53c..604f7326 100644 --- a/nonebot/__init__.py +++ b/nonebot/__init__.py @@ -199,8 +199,12 @@ def init(*, _env_file: Optional[str] = None, **kwargs): logger.opt(colors=True).debug( f"Loaded Config: {escape_tag(str(config.dict()))}") - DriverClass: Type[Driver] = getattr( - importlib.import_module(config.driver), "Driver") + modulename, _, cls = config.driver.partition(":") + module = importlib.import_module(modulename) + instance = module + for attr_str in (cls or "Driver").split("."): + instance = getattr(instance, attr_str) + DriverClass: Type[Driver] = instance # type: ignore _driver = DriverClass(env, config) diff --git a/nonebot/config.py b/nonebot/config.py index ae82a3b6..732146df 100644 --- a/nonebot/config.py +++ b/nonebot/config.py @@ -144,6 +144,8 @@ class Config(BaseConfig): :说明: NoneBot 运行所使用的 ``Driver`` 。继承自 ``nonebot.driver.BaseDriver`` 。 + + 配置格式为 ``[:]``,默认类名为 ``Driver``。 """ host: IPvAnyAddress = IPv4Address("127.0.0.1") # type: ignore """