添加 Debug 调试任务和运行 bot 的 task

This commit is contained in:
2025-09-28 20:31:18 +08:00
parent d6d68dcc96
commit a727c108fe
3 changed files with 41 additions and 1 deletions

24
.vscode/launch.json vendored Normal file
View File

@ -0,0 +1,24 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "运行 Bot 并调试(自动重载)",
"type": "debugpy",
"request": "launch",
"module": "watchfiles",
"args": [
"bot.main"
],
"console": "integratedTerminal",
"justMyCode": true,
"env": {
"PYTHONPATH": "${workspaceFolder}"
},
"cwd": "${workspaceFolder}",
"presentation": {
"hidden": false,
"group": "bot"
}
}
]
}

13
.vscode/tasks.json vendored
View File

@ -12,6 +12,19 @@
},
"problemMatcher": [],
"detail": "导出生产环境依赖到 requirements.txt"
},
{
"label": "Bot: Run with Auto-reload",
"type": "shell",
"command": "poetry run watchfiles bot.main",
"group": "build",
"isBackground": true,
"presentation": {
"reveal": "always",
"panel": "new"
},
"problemMatcher": [],
"detail": "运行 bot 并启用自动重载功能"
}
]
}

5
bot.py
View File

@ -14,7 +14,7 @@ env_enable_qq = os.environ.get("ENABLE_QQ", "none")
env_enable_discord = os.environ.get("ENABLE_DISCORD", "none")
env_enable_minecraft = os.environ.get("ENABLE_MINECRAFT", "none")
if __name__ == "__main__":
def main():
nonebot.init()
driver = nonebot.get_driver()
@ -35,3 +35,6 @@ if __name__ == "__main__":
nonebot.load_plugins("konabot/plugins")
nonebot.run()
if __name__ == "__main__":
main()