用nonebot2模块创建QQ机器人,基于的原理应是反向协议,其中bot.py的代码如下:
import nonebot
from nonebot.adapters.onebot.v12 import Adapter as ONEBOT_V12Adapter
# Custom your logger
#
# from nonebot.log import logger, default_format
# logger.add("error.log",
# rotation="00:00",
# diagnose=False,
# level="ERROR",
# format=default_format)
# You can pass some keyword args config to init function
nonebot.init()
app = nonebot.get_asgi()
driver = nonebot.get_driver()
driver.register_adapter(ONEBOT_V12Adapter)
nonebot.load_builtin_plugins("single_session")
# Please DO NOT modify this file unless you know what you are doing!
# As an alternative, you should use command `nb` or modify `pyproject.toml` to load plugins
nonebot.load_from_toml("pyproject.toml")
# Modify some config / config depends on loaded configs
#
# config = driver.config
# do something...
if __name__ == "__main__":
nonebot.logger.warning("Always use `nb run` to start the bot instead of manually running!")
nonebot.run(app="__mp_main__:app")
当所有文件配置好时,按理讲最后一步就是运行这个文件了,可当运行时发生如下报错:
Traceback (most recent call last):
File "C:/Users/MacBooK/毛森/bot.py", line 5, in <module>
from nonebot.adapters.onebot.v12 import Adapter as ONEBOT_V12Adapter
ModuleNotFoundError: No module named 'nonebot.adapters'
按照报错的意思处理后,安装'nonebot.adapters'报错如下:
ERROR: Could not find a version that satisfies the requirement nonebot.adapters (from versions: none)
ERROR: No matching distribution found for nonebot.adapters
然后就是剩下一脸懵逼的我了……求各位指点,将万分感激!