๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป V2 Tutorial: Deploy your Discord Bot to Heroku โ€” Part 2

Renemari Padillo
Davao JS
Published in
3 min readFeb 4, 2020

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

This instruction is very straight forward the only thing you need to do is to follow it line-by-line into your terminal.

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 ๐Ÿ‘Š๐Ÿผ

--

--

Renemari Padillo
Davao JS
Editor for

Things I do: ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป ๐ŸŽฎ ๐Ÿ“ธ ๐Ÿšด๐Ÿผ ๐Ÿ›ซ(repeat) โ€ข https://renesansz.me