> 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).

# 从个人服务器托管 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=<a unique key you get once you sign-up with Convai>

   # 使用 Convai 创建的新角色的 character-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.
