Dockerize discord bot and update docs to run the bot correctly (#919)

This commit is contained in:
Sidharth Mohanty
2023-11-08 23:54:57 +05:30
committed by GitHub
parent 98eb5b54be
commit 6864b4207b
3 changed files with 36 additions and 22 deletions

View File

@@ -1,5 +1,5 @@
--- ---
title: '🤖 Discord Bot' title: "🤖 Discord Bot"
--- ---
### 🔑 Keys Setup ### 🔑 Keys Setup
@@ -12,9 +12,11 @@ title: '🤖 Discord Bot'
- On the left sidebar, click on `OAuth2` and go to `General`. - On the left sidebar, click on `OAuth2` and go to `General`.
- Set `Authorization Method` to `In-app Authorization`. Under `Scopes` select `bot`. - Set `Authorization Method` to `In-app Authorization`. Under `Scopes` select `bot`.
- Under `Bot Permissions` allow the following and then click on `Save Changes`. - Under `Bot Permissions` allow the following and then click on `Save Changes`.
```text ```text
Send Messages (under Text Permissions) Send Messages (under Text Permissions)
``` ```
- Now under `OAuth2` and go to `URL Generator`. Under `Scopes` select `bot`. - Now under `OAuth2` and go to `URL Generator`. Under `Scopes` select `bot`.
- Under `Bot Permissions` set the same permissions as above. - Under `Bot Permissions` set the same permissions as above.
- Now scroll down and copy the `Generated URL`. Paste it in a browser window and select the Server where you want to add the bot. - Now scroll down and copy the `Generated URL`. Paste it in a browser window and select the Server where you want to add the bot.
@@ -23,40 +25,46 @@ Send Messages (under Text Permissions)
### Take the bot online ### Take the bot online
1. Install embedchain python package: <Tabs>
<Tab title="docker">
```bash
docker run --name discord-bot -e OPENAI_API_KEY=sk-xxx -e DISCORD_BOT_TOKEN=xxx -p 8080:8080 embedchain/discord-bot:latest
```
</Tab>
<Tab title="python">
```bash ```bash
pip install --upgrade "embedchain[discord]" pip install --upgrade "embedchain[discord]"
```
2. Launch your Discord bot:
```bash
python -m embedchain.bots.discord python -m embedchain.bots.discord
```
If you prefer to see the question and not only the answer, run it with # or if you prefer to see the question and not only the answer, run it with
```bash
python -m embedchain.bots.discord --include-question python -m embedchain.bots.discord --include-question
``` ```
</Tab>
</Tabs>
### 🚀 Usage Instructions ### 🚀 Usage Instructions
- Go to the server where you have added your bot. - Go to the server where you have added your bot.
![Slash commands interaction with bot](https://github.com/embedchain/embedchain/assets/73601258/bf1414e3-d408-4863-b0d2-ef382a76467e)
- You can add data sources to the bot using the slash command: - You can add data sources to the bot using the slash command:
```text ```text
/add <data_type> <url_or_text> /ec add <data_type> <url_or_text>
``` ```
- You can ask your queries from the bot using the slash command: - You can ask your queries from the bot using the slash command:
```text ```text
/query <question> /ec query <question>
``` ```
- You can chat with the bot using the slash command: - You can chat with the bot using the slash command:
```text ```text
/chat <question> /ec chat <question>
``` ```
📝 Note: To use the bot privately, you can message the bot directly by right clicking the bot and selecting `Message`. 📝 Note: To use the bot privately, you can message the bot directly by right clicking the bot and selecting `Message`.
🎉 Happy Chatting! 🎉 🎉 Happy Chatting! 🎉

View File

@@ -1,4 +1,4 @@
FROM python:3.11 AS backend FROM python:3.11-slim
WORKDIR /usr/src/discord_bot WORKDIR /usr/src/discord_bot
COPY requirements.txt . COPY requirements.txt .

View File

@@ -1,3 +1,9 @@
# Discord Bot # Discord Bot
This is a docker template to create your own Discord bot using the embedchain package. To know more about the bot and how to use it, go [here](https://docs.embedchain.ai/examples/discord_bot). This is a docker template to create your own Discord bot using the embedchain package. To know more about the bot and how to use it, go [here](https://docs.embedchain.ai/examples/discord_bot).
To run this use the following command,
```bash
docker run --name discord-bot -e OPENAI_API_KEY=sk-xxx -e DISCORD_BOT_TOKEN=xxx -p 8080:8080 embedchain/discord-bot:latest
```