18870 / nonebot-plugin-reboot

命令重启 nonebot2
MIT License
17 stars 0 forks source link

关于插件加载两次的问题 #6

Closed ElainaFanBoy closed 1 year ago

ElainaFanBoy commented 1 year ago

大佬,可否请教一下bot.py点具体写法,我没有pyproject.toml,只靠文件夹加载插件

18870 commented 1 year ago

我自己用的项目结构比较旧了,仅供参考

import nonebot
from nonebot.adapters.onebot.v11 import Adapter as ONEBOT_V11Adapter

nonebot.init()

driver = nonebot.get_driver()
driver.register_adapter(ONEBOT_V11Adapter)

+ if __name__ == "__mp_main__":
+     nonebot.load_plugins("src/plugins")

if __name__ == "__main__":
+     nonebot.load_plugin("nonebot_plugin_reboot")
    nonebot.run()

使用 pyproject.toml 的版本

import nonebot
from nonebot.adapters.onebot.v11 import Adapter as ONEBOT_V11Adapter

nonebot.init()

driver = nonebot.get_driver()
driver.register_adapter(ONEBOT_V11Adapter)

if __name__ == "__mp_main__":
    nonebot.load_from_toml("pyproject.toml")

if __name__ == "__main__":
    nonebot.load_plugin("nonebot_plugin_reboot")
    nonebot.run()