(window.webpackJsonp=window.webpackJsonp||[]).push([[200],{465:function(t,e,s){"use strict";s.r(e);var v=s(21),a=Object(v.a)({},(function(){var t=this,e=t.$createElement,s=t._self._c||e;return s("ContentSlotsDistributor",{attrs:{"slot-key":t.$parent.slotKey}},[s("h1",{attrs:{id:"创建一个完整的项目"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#创建一个完整的项目"}},[t._v("#")]),t._v(" 创建一个完整的项目")]),t._v(" "),s("p",[t._v("上一章中我们已经运行了一个简单的 NoneBot 实例，在这一章，我们将从零开始一个完整的项目。")]),t._v(" "),s("h2",{attrs:{id:"目录结构"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#目录结构"}},[t._v("#")]),t._v(" 目录结构")]),t._v(" "),s("p",[t._v("可以使用 "),s("code",[t._v("nb-cli")]),t._v(" 或者自行创建完整的项目目录：")]),t._v(" "),s("div",{staticClass:"language-bash line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("nb create\n")])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br")])]),t._v(" "),s("pre",{staticClass:"vue-container"},[s("code",[s("p",[t._v("AweSome-Bot\n├── "),s("code",[t._v("awesome_bot")]),t._v(" "),s("em",[t._v("("),s("strong",[t._v("或是 src")]),t._v(")")]),t._v("\n│   └── "),s("code",[t._v("plugins")]),t._v("\n├── "),s("code",[t._v(".env")]),t._v(" "),s("em",[t._v("("),s("strong",[t._v("可选的")]),t._v(")")]),t._v("\n├── "),s("code",[t._v(".env.dev")]),t._v(" "),s("em",[t._v("("),s("strong",[t._v("可选的")]),t._v(")")]),t._v("\n├── "),s("code",[t._v(".env.prod")]),t._v(" "),s("em",[t._v("("),s("strong",[t._v("可选的")]),t._v(")")]),t._v("\n├── .gitignore\n├── "),s("code",[t._v("bot.py")]),t._v("\n├── docker-compose.yml\n├── Dockerfile\n├── "),s("code",[t._v("pyproject.toml")]),t._v("\n└── README.md")]),t._v("\n")])]),t._v(" "),s("ul",[s("li",[s("code",[t._v("awesome_bot/plugins")]),t._v(" 或 "),s("code",[t._v("src/plugins")]),t._v(": 用于存放编写的 bot 插件")]),t._v(" "),s("li",[s("code",[t._v(".env")]),t._v(", "),s("code",[t._v(".env.dev")]),t._v(", "),s("code",[t._v(".env.prod")]),t._v(": 各环境配置文件")]),t._v(" "),s("li",[s("code",[t._v("bot.py")]),t._v(": bot 入口文件")]),t._v(" "),s("li",[s("code",[t._v("pyproject.toml")]),t._v(": 项目依赖管理文件，默认使用 "),s("a",{attrs:{href:"https://python-poetry.org/",target:"_blank",rel:"noopener noreferrer"}},[t._v("poetry"),s("OutboundLink")],1)])]),t._v(" "),s("h2",{attrs:{id:"启动-bot"}},[s("a",{staticClass:"header-anchor",attrs:{href:"#启动-bot"}},[t._v("#")]),t._v(" 启动 Bot")]),t._v(" "),s("div",{staticClass:"custom-block warning"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("如果您使用如 "),s("code",[t._v("VSCode")]),t._v(" / "),s("code",[t._v("PyCharm")]),t._v(" 等 IDE 启动 nonebot，请检查 IDE 当前工作空间目录是否与当前侧边栏打开目录一致。")]),t._v(" "),s("ul",[s("li",[t._v("在二者不一致的环境下可能导致 nonebot 读取配置文件和插件等不符合预期")])])]),t._v(" "),s("p",[t._v("通过 "),s("code",[t._v("nb-cli")])]),t._v(" "),s("div",{staticClass:"language-bash line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("nb run "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("--file"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("bot.py"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v(" "),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("[")]),t._v("--app"),s("span",{pre:!0,attrs:{class:"token operator"}},[t._v("=")]),t._v("app"),s("span",{pre:!0,attrs:{class:"token punctuation"}},[t._v("]")]),t._v("\n")])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br")])]),s("p",[t._v("或")]),t._v(" "),s("div",{staticClass:"language-bash line-numbers-mode"},[s("pre",{pre:!0,attrs:{class:"language-bash"}},[s("code",[t._v("python bot.py\n")])]),t._v(" "),s("div",{staticClass:"line-numbers-wrapper"},[s("span",{staticClass:"line-number"},[t._v("1")]),s("br")])]),s("div",{staticClass:"custom-block tip"},[s("p",{staticClass:"custom-block-title"},[t._v("提示")]),t._v(" "),s("p",[t._v("如果在 bot 入口文件内定义了 asgi server， "),s("code",[t._v("nb-cli")]),t._v(" 将会为你启动"),s("strong",[t._v("冷重载模式")]),t._v("（当文件发生变动时自动重启 NoneBot 实例）")])])])}),[],!1,null,null,null);e.default=a.exports}}]);