mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-09-04 02:56:45 +00:00
📝 Docs: 更新文档《手动创建项目》 (#3623)
Some checks failed
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.11) (push) Failing after 3s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.12) (push) Failing after 3s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.10) (push) Failing after 3s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.11) (push) Failing after 2s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.9) (push) Failing after 2s
Pyright Lint / Pyright Lint (pydantic-v1) (push) Failing after 2s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.9) (push) Failing after 6s
Ruff Lint / Ruff Lint (push) Failing after 2s
Site Deploy / publish (push) Failing after 2s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.10) (push) Failing after 12s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.12) (push) Failing after 13s
Pyright Lint / Pyright Lint (pydantic-v2) (push) Failing after 17s
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.9) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.9) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.9) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.9) (push) Has been cancelled
Some checks failed
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.11) (push) Failing after 3s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.12) (push) Failing after 3s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.10) (push) Failing after 3s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.11) (push) Failing after 2s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.9) (push) Failing after 2s
Pyright Lint / Pyright Lint (pydantic-v1) (push) Failing after 2s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.9) (push) Failing after 6s
Ruff Lint / Ruff Lint (push) Failing after 2s
Site Deploy / publish (push) Failing after 2s
Code Coverage / Test Coverage (pydantic-v1, ubuntu-latest, 3.10) (push) Failing after 12s
Code Coverage / Test Coverage (pydantic-v2, ubuntu-latest, 3.12) (push) Failing after 13s
Pyright Lint / Pyright Lint (pydantic-v2) (push) Failing after 17s
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.9) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, macos-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v1, windows-latest, 3.9) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, macos-latest, 3.9) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.10) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.11) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.12) (push) Has been cancelled
Code Coverage / Test Coverage (pydantic-v2, windows-latest, 3.9) (push) Has been cancelled
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com> Co-authored-by: StarHeartHunt <starheart233@gmail.com>
This commit is contained in:
@ -10,6 +10,9 @@ options:
|
||||
|
||||
# 手动创建项目
|
||||
|
||||
import Tabs from "@theme/Tabs";
|
||||
import TabItem from "@theme/TabItem";
|
||||
|
||||
在[快速上手](../quick-start.mdx)中,我们已经介绍了如何安装和使用 `nb-cli` 创建一个项目。在本章节中,我们将简要介绍如何在不使用 `nb-cli` 的方式创建一个机器人项目的**最小实例**并启动。如果你想要了解 NoneBot 的启动流程,也可以阅读本章节。
|
||||
|
||||
:::caution 警告
|
||||
@ -30,23 +33,45 @@ options:
|
||||
|
||||
1. (可选)创建虚拟环境,以 venv 为例
|
||||
|
||||
<Tabs groupId="platform"><TabItem value="windows" label="Windows" default>
|
||||
|
||||
```bash
|
||||
# 创建虚拟环境
|
||||
python -m venv .venv --prompt nonebot2
|
||||
# windows
|
||||
# 激活虚拟环境
|
||||
.venv\Scripts\activate
|
||||
# linux/macOS
|
||||
```
|
||||
|
||||
</TabItem><TabItem value="linux/macos" label="Linux/macOS">
|
||||
|
||||
```bash
|
||||
# 创建虚拟环境
|
||||
python -m venv .venv --prompt nonebot2
|
||||
# 激活虚拟环境
|
||||
source .venv/bin/activate
|
||||
```
|
||||
|
||||
2. 安装 nonebot2 以及驱动器
|
||||
</TabItem></Tabs>
|
||||
|
||||
2. 安装 nonebot2 以及驱动器,以 Fastapi 驱动器为例
|
||||
|
||||
<Tabs groupId="platform"><TabItem value="windows" label="Windows" default>
|
||||
|
||||
```bash
|
||||
pip install 'nonebot2[fastapi]'
|
||||
pip install "nonebot2[fastapi]"
|
||||
```
|
||||
|
||||
驱动器包名可以在 [驱动器商店](/store/drivers) 中找到。
|
||||
</TabItem><TabItem value="linux/macos" label="Linux/macOS">
|
||||
|
||||
3. 安装适配器
|
||||
```bash
|
||||
pip install "nonebot2[fastapi]"
|
||||
```
|
||||
|
||||
</TabItem></Tabs>
|
||||
|
||||
驱动器包名可以在 [驱动器商店](/store/drivers) 中找到,请替换上文方括号中的内容。
|
||||
|
||||
3. 安装适配器,以 Console 适配器为例
|
||||
|
||||
```bash
|
||||
pip install nonebot-adapter-console
|
||||
@ -58,7 +83,7 @@ options:
|
||||
|
||||
配置文件用于存放 NoneBot 运行所需要的配置项,使用 [`pydantic`](https://docs.pydantic.dev/) 以及 [`python-dotenv`](https://saurabh-kumar.com/python-dotenv/) 来读取配置。配置项需符合 dotenv 格式,复杂类型数据需使用 JSON 格式填写。具体可选配置方式以及配置项详情参考[配置](../appendices/config.mdx)。
|
||||
|
||||
在**项目文件夹**中创建一个 `.env` 文本文件,并写入以下内容:
|
||||
在**项目文件夹**中创建一个名为 `.env` 的文件,并写入以下内容:
|
||||
|
||||
```bash title=.env
|
||||
HOST=0.0.0.0 # 配置 NoneBot 监听的 IP / 主机名
|
||||
@ -101,10 +126,29 @@ if __name__ == "__main__":
|
||||
|
||||
## 运行机器人
|
||||
|
||||
在**项目文件夹**中,使用配置好环境的 Python 解释器运行入口文件(如果使用虚拟环境,请先激活虚拟环境):
|
||||
在**项目文件夹**中,使用配置好环境的 Python 解释器运行入口文件:
|
||||
|
||||
<Tabs groupId="platform">
|
||||
<TabItem value="windows" label="Windows" default>
|
||||
|
||||
```bash
|
||||
# 激活虚拟环境(未使用虚拟环境时跳过此行)
|
||||
.venv\Scripts\activate
|
||||
# 运行机器人
|
||||
python bot.py
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
<TabItem value="linux/macos" label="Linux/macOS">
|
||||
|
||||
```bash
|
||||
# 激活虚拟环境(未使用虚拟环境时跳过此行)
|
||||
source .venv/bin/activate
|
||||
# 运行机器人
|
||||
python bot.py
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
</Tabs>
|
||||
|
||||
如果你后续使用了 `nb-cli` ,你仍可以使用 `nb run` 命令来运行机器人,`nb-cli` 会自动检测入口文件 `bot.py` 是否存在并运行。同时,你也可以使用 `nb run --reload` 来自动检测代码的更改并自动重新运行入口文件。
|
@ -64,7 +64,7 @@ options:
|
||||
:::
|
||||
|
||||
:::caution 注意
|
||||
如果在之前的[创建项目](./application.md)章节中手动创建了相关文件,那么你需要做出如下修改:
|
||||
如果在之前的[创建项目](./application.mdx)章节中手动创建了相关文件,那么你需要做出如下修改:
|
||||
|
||||
1. 在项目目录中创建一个两层文件夹 `awesome_bot/plugins`
|
||||
|
||||
|
Reference in New Issue
Block a user