DEV Community

Khanmanan
Khanmanan

Posted on

How to host discord bot 24/7 using Heroku

Hey everyone, in this quick tutorial I'm going to show you how to host your discord bot 24/7 for free using Heroku.

Hhh What you'll need:

-A discord bot (duh)
-Some knowledge of Javascript and the Discord.js library
-A Heroku account (sign up here: https://signup.heroku.com/)

Once you have all of that, head over to your Heroku account and create a new app. Give it a name (this can be anything) and set the region to whichever is closest to you. After that, select "Create App".

Once the app has been created, head over to the "Deploy" tab and scroll down to the "Manual Deploy" section. Select the branch you want to deploy from (usually this will be "master") and click "Deploy Branch". Now, wait for the deploy to finish.Once it has finished, head over to the "Resources" tab and click "Add a resource". Search for "Heroku Scheduler" and select it. Once you've added the Scheduler, head over to the "Settings" tab and click "Reveal Config Vars". You will need to set two config variables: BOT_TOKEN and CLIENT_ID. The BOT_TOKEN is your bot's token (you can find this in the discord developer portal) and the CLIENT_ID is your Discord application's client ID (also found in the developer portal).After you've set those, head over to the "Heroku Scheduler" tab and create a new job. In the "Command" field, type in "node bot.js" (or whatever your main file is called) and in the "Frequency" field, select how often you want your bot to be restarted. I usually just set mine to "Daily". After that, click "Add Job" and you're all done! Your bot should now be up and running 24/7.

If you have any questions, feel free to leave them in the comments below and I'll try to get back to you as soon as I can.

As always, thanks for reading and I hope this helped you out.

Image.png

Top comments (0)