๐จ๐ปโ๐ป V2 Tutorial: Deploy your Discord Bot to Heroku โ Part 2
Hey everyone ๐, welcome to the second and the last part of the tutorial. For new comers who havenโt seen the first part check it out here.
Quick Recap
In the first part, we have setup our code, discord account, and discord bot into our test channel.
Now we will host our bot to Heroku to be able to keep our bot running without relying in our local host.
DISCLAIMER: Please do note that in this tutorial Iโll be using free plan, I canโt guarantee your bot will run 24/7 due to the limitations (unless you can afford to pay). But please do share if you have better alternatives than Heroku ๐
Prerequisites
- You must have a Heroku Account, you can sign up here
- Must have Heroku CLI installed
Deploying and running your bot in Heroku
Login into your account and create your Heroku App
Then youโll be redirected to this page
First, we need to inform Heroku that we have DISCORD_TOKEN to be injected when we deploy, go to Settings
Then click on Reveal Config Vars, and add the token we have inside the .env file, then click โAddโ
Go back to the Deploy page, and follow the instructions under Deploy Using Heroku Git
One you push your code to Heroku, your terminal should show a success message, something like this:
Your bot should be up and running in a few seconds, now go to your Discord channel and you should see that your bot is online and will respond to you once you send a message โpingโ
Update FIX โ April 04, 2020
I was told that the bot script gets an error at a certain time when hosted in Heroku, unfortunately it does not restart by itself. To fix this you need to add a Procfile in your root project folder with the following code:
worker: npm run start
Once done simply add, commit, and push your code into your Heroku app.
Thanks to mr-winston for letting me know of the issue.
CONGRATULATIONS! ๐ your bot is now up and running!
I apologize that it took some time before I posted the second part of the tutorial, but I hope you have learned something on this.
Let me know if you have question(s) or problem(s) with your setup and create your issues here.
Have fun and keep learning ๐๐ผ