How to Host Discord Bots on Heroku for FREE: A Guide
Want to keep your discord bots online 24/7? For free? Heroku is one of the platforms that you can do so, and I am here to teach you how to do it :3 Listen up and listen well!
Basically, Heroku is a cloud platform service that supports many different programming languages.
Step 1: Make sure that you have your codes in a folder. Do you have them? Mine looks like this:
First thing to note: NEVER PUT YOUR TOKEN INTO YOUR FILES. Remember that secret token I told you about in the guide on how to set up your bot? Take it out from your index.js and hold on to it.
Instead, replace it with:
client.login(process.env.token);
Now once you have done that, save your index.js file and create a new file like the one you see there (see that purple looking file in the image above?)
Create a new file and name it "Procfile".
And all you need in that file is:
That's all. Once you've done that, let's move on to step 2!
Step 2: Upload your files onto your Github.
Github is where you usually upload your codes, like a repository. I'm not really going to teach you how to upload, I'm sure there are loads of tutorials out there showing it, BUT if you still need help, you can DM me on Discord or send me an Ask here n.n
MAKE SURE YOU MAKE YOUR REPOSITORY PUBLIC.
Alright then. Time to make a heroku account!
Step 3: Go to the website HERE and sign up for a new account.
It doesn't really matter what you put on that first page. Make sure you're not a robot and click CREATE FREE ACCOUNT.
Step 4: CONFIRM YOUR ACCOUNT. Like, go into the email that you signed up with and click that little link that asks you to confirm it n.n And then, set your password and you're IN. FINALLY.
Step 5: Read the terms and conditions. And errr, if you're based in Italy, change that option to YES. Otherwise, click Accept.
Step 6: Click Create a new app > Find a name for your application and then click Create app.
Step 7: Before you do ANYTHING else, go to Deploy > Github and connect your Github repository to the Heroku application.
Step 8: Once you are connected to your Github repository, click on Settings at the top bar of your application and scroll down to Config Vars and click on Reveal Config Vars.
From here, under KEY, type in token and under VALUE, put in your discord secret token.
And then click ADD.
That is where Heroku will take your token from, and into your code. Remember that client.login(process.env.token)? :3
FINALLY the step to give you free Heroku account!
Step 9: Click on Resources from the top tab and you will see this:
Make sure you turn on Worker: node index.js! You can do this by clicking on pencil icon next to it. If you don't see this, you can click on Change Dyno Type > Free account and save.
TADAAAA!
Note: You are only given free 550 hours PER MONTH and if you calculate, that isn't exactly enough if you want to keep your bot running 24/7 in a month. What you can do is connect your credit card or debit card to the account and you will get 450 more hours. So in total that is 1000 hours per month, which is more than enough!
I know what you're thinking: that you might get charged unnecessarily if you connect your card! But nope, you don't get charged AT ALL. I've been using this account for more than a year and I never once was charged for it.
How to connect to your credit/debit card? Go to your account at the top right hand of the website (that little human logo) and click Account Settings. From there, click on Billing and connect your credit/debit card!
BUT IF YOU'RE UNSURE ABOUT CONNECTING, you can just use the 550 hours. Just note that your bot will be down once that 550 hours are up every month n.n
WE'RE NOT DONE YET, it's time to bring your bot to life!
Step 10: Click on Deploy from the top tabs and scroll down until you see Deploy Branch. Click on that, quick quick! :3
You will see the words saying "Your app was successfully deployed." And tadaaaa, your discord bot is up :3
I hope that was easy to follow and if it's not, you can ask me for more help. DM me on Discord at Maryam#9206 or you can send me an Ask here! :3