> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/other-integrations/discord/hosting-discord-bot-from-personal-server.md). Agents can also search and read this documentation through its [MCP server](https://docs.convai.com/api-docs/~gitbook/mcp).

# 从个人服务器托管 Discord Bot

成功托管一个连接到 Convai API 的 Discord Bot 服务器

下面列出了成功托管 Discord 机器人服务器的步骤，以及更新必要信息的方法，以便用户能够与创建的角色顺畅交流。

{% hint style="info" %}
当前版本仅支持 Python。我们正努力支持使用其他语言编写的服务器。如有任何疑问，请通过 <support@convai.com> 联系我们。
{% endhint %}

代码链接： [Github](https://github.com/Conv-AI/Convai_Discord_Integration)

步骤：

1. 访问上方链接，并将代码仓库克隆到你要托管服务器的系统中。

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2FodZ65G97ZmjijiMGsmVE%2Fdbh-ss-1.png?alt=media&amp;token=25393cd9-df7b-4492-afde-97fa0f4592f2" alt=""><figcaption></figcaption></figure>
2. 在系统中打开 **终端**
3. 输入以下命令：

   ```bash
   $ git clone https://github.com/Conv-AI/Convai_Discord_Integration.git

   $ cd Convai_Discord_Integration

   $ cd python/
   ```
4. 现在我们进入了包含必要代码的 **python** 文件夹。
5. 我们需要编辑 **.env** 文件，填入必要的凭据。打开 .**env** 文件进行编辑，并填写必要的信息。

   ```
   # Discord 为你的机器人生成的唯一令牌
   DISCORD_BOT_TOKEN=<the token that we received from Step 13 while creating Discord Bot>

   # 创建 Convai 账户后获取的唯一 API 密钥。
   CONVAI_API_KEY=<the unique key you get once you sign-up with Convai>

   # 在 Convai 中创建的新角色的角色 ID
   CONVAI_CHARACTER_ID=<a unique id to identify the character that we got while creating the character in Convai website>

   # 每次查询时，用于从 Convai 服务器获取响应的 URL
   CHARACTER_GET_RESPONSE_URL=https://api.convai.com/character/getResponse

   # 启用语音响应，以生成将在语音频道中播放的音频文件。当前仍在开发中
   ENABLE_VOICE_RESPONSE=False

   # 列出你希望机器人响应的所有频道，以逗号 ',' 分隔
   # ALLOWED_CHANNELS=welcome,general,...
   ALLOWED_CHANNELS= <如果希望机器人响应所有频道，请留空>
   ```
6. 完成这些设置后，就可以启动服务器了，只需运行以下命令：

   ```bash
   $ python main.py
   ```
7. 现在机器人应该已经正常运行。你会看到类似这样的日志，表明机器人已启动。

   <figure><img src="https://2402152281-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FEtUJA212Zc1S9ACc8T4l%2Fuploads%2Fu6roSjS2wYIVEKXcswyj%2Fdbh-ss-2.png?alt=media&amp;token=61452302-260d-4c16-9134-00b85feea04c" alt=""><figcaption></figcaption></figure>

   注意：这里的 ConvaiBot 是我们设置的名称。你的机器人名称会显示在这里，替代 ConvaiBot。

到这里就完成了。你的机器人已启动。请保持它运行，以便与用户互动。

{% hint style="warning" %}
如果托管过程中遇到问题，请通过 <support@convai.com> 联系我们，我们会尽快回复。

Convai 正在寻找替你托管机器人服务器的解决方案，这样你就不必经历上述步骤中的繁琐操作。一旦有新进展，我们会及时更新文档。
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/other-integrations/discord/hosting-discord-bot-from-personal-server.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
