discord_bot.mdx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. 1. Install embedchain python package:
  23. ```bash
  24. pip install --upgrade "embedchain[discord]"
  25. ```
  26. 2. Launch your Discord bot:
  27. ```bash
  28. python -m embedchain.bots.discord
  29. ```
  30. If you prefer to see the question and not only the answer, run it with
  31. ```bash
  32. python -m embedchain.bots.discord --include-question
  33. ```
  34. ### 🚀 Usage Instructions
  35. - Go to the server where you have added your bot.
  36. - You can add data sources to the bot using the slash command:
  37. ```text
  38. /add <data_type> <url_or_text>
  39. ```
  40. - You can ask your queries from the bot using the slash command:
  41. ```text
  42. /query <question>
  43. ```
  44. 📝 Note: To use the bot privately, you can message the bot directly by right clicking the bot and selecting `Message`.
  45. 🎉 Happy Chatting! 🎉