discord_bot.mdx 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. ---
  2. title: "🤖 Discord Bot"
  3. ---
  4. ### 🔑 Keys Setup
  5. - Set your `OPENAI_API_KEY` in your variables.env file.
  6. - Go to [https://discord.com/developers/applications/](https://discord.com/developers/applications/) and click on `New Application`.
  7. - Enter the name for your bot, accept the terms and click on `Create`. On the resulting page, enter the details of your bot as you like.
  8. - On the left sidebar, click on `Bot`. Under the heading `Privileged Gateway Intents`, toggle all 3 options to ON position. Save your changes.
  9. - Now click on `Reset Token` and copy the token value. Set it as `DISCORD_BOT_TOKEN` in .env file.
  10. - On the left sidebar, click on `OAuth2` and go to `General`.
  11. - Set `Authorization Method` to `In-app Authorization`. Under `Scopes` select `bot`.
  12. - Under `Bot Permissions` allow the following and then click on `Save Changes`.
  13. ```text
  14. Send Messages (under Text Permissions)
  15. ```
  16. - Now under `OAuth2` and go to `URL Generator`. Under `Scopes` select `bot`.
  17. - Under `Bot Permissions` set the same permissions as above.
  18. - 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.
  19. - Click on `Continue` and authorize the bot.
  20. - 🎉 The bot has been successfully added to your server. But it's still offline.
  21. ### Take the bot online
  22. <Tabs>
  23. <Tab title="docker">
  24. ```bash
  25. docker run --name discord-bot -e OPENAI_API_KEY=sk-xxx -e DISCORD_BOT_TOKEN=xxx -p 8080:8080 embedchain/discord-bot:latest
  26. ```
  27. </Tab>
  28. <Tab title="python">
  29. ```bash
  30. pip install --upgrade "embedchain[discord]"
  31. python -m embedchain.bots.discord
  32. # or if you prefer to see the question and not only the answer, run it with
  33. python -m embedchain.bots.discord --include-question
  34. ```
  35. </Tab>
  36. </Tabs>
  37. ### 🚀 Usage Instructions
  38. - Go to the server where you have added your bot.
  39. ![Slash commands interaction with bot](https://github.com/embedchain/embedchain/assets/73601258/bf1414e3-d408-4863-b0d2-ef382a76467e)
  40. - You can add data sources to the bot using the slash command:
  41. ```text
  42. /ec add <data_type> <url_or_text>
  43. ```
  44. - You can ask your queries from the bot using the slash command:
  45. ```text
  46. /ec query <question>
  47. ```
  48. - You can chat with the bot using the slash command:
  49. ```text
  50. /ec chat <question>
  51. ```
  52. 📝 Note: To use the bot privately, you can message the bot directly by right clicking the bot and selecting `Message`.
  53. 🎉 Happy Chatting! 🎉