This is a starter project for building discord bots.
Features:
- API to handle registering/unregistering discord commands
- queue support for long running tasks
- deployed to a serverless infrastructure
- implements the discord verification flow to correctly register a bot webhook
- lightweight codebase - written in typescript using Discord webhooks which makes the code very simple and easy to understand
I am especially proud of this template because it runs long running tasks such as OpenAI calls in the background using a queue system. This enables the bot to be run on a serverless infrastructure, which is very cheap and easy to scale.
This discord bot is deployed with genezio
because it's easy to use and it has a generous free tier plan.
Genezio deploys to a serverless infrastructure, so I don't have to worry about scaling or managing servers.
Deploy the bot by running the following command:
cd ./server && genezio deploy
To have queue support, go to https://app.genez.io/, select your project and enable the QStash Queue integration.
Also, you need to set the following environment variables in the corresponding project page:
# Get them from https://discord.com/developers/applications
DISCORD_TOKEN=
DISCORD_APPLICATION_ID=
DISCORD_PUBLIC_KEY=
# Get it from https://app.genez.io or from your terminal after deploying
QUEUE_WEBHOOK_URL=
Your discord bot is now deployed and ready to use! Head to the Discord Developer Portal to copy the bot invite URL and add it to your server.
You can use the testing dashboard from app.genez.io to register/unregister commands for your bot.
I encourage you to fork this template and build your own discord bot on top of it.
I strongly believe this is a great starter that, essentially, costs you nothing to use and you can do pretty great things starting from here.
You can also test the bot locally by using a proxy server such as ngrok.
Start the local server by running:
genezio local
Then, expose the local webhook with ngrok by running:
ngrok http 8083
Use the URL generated by ngrok to register the webhook in the Discord Developer Portal and as an environment variable in the Genezio project page.
If you need any help running the bot, feel free to drop an issue.
Also, I am excited to improve this template, so feel free to open an [issue(https://github.com/andreia-oca/discord_bot_template/issues)] with feature requests or a PR to contribute to it.
- Add an admin dashboard to manage the bot commands
- Add analytics to track bot usage
- Integrate it with Reddit, Twitter, GitHub etc. to publish content to a Discord server
- Discord Developer Portal: https://discord.com/developers/applications
- Genezio Webhook Documentation: https://docs.genez.io/genezio-documentation/webhooks