-
-
Notifications
You must be signed in to change notification settings - Fork 18
The Heroku Hosting
After writing your code and after running it successfully on your local machine, its time to host it on a cloud platform
Well they are typically hundreds and hundreds of computers in underground bunkers that will host your code or rather anyone's code or software at a given price or for free. Some of the examples are Google Cloud, Amazon Web Services, Heroku etc.
This tutorial will cover the steps to host your bot on the Heroku platform. Heroku provides 550 free hours per dyno (don't worry about that term yet) and it gives an additional 450 hours if you verify your credit card. Usually Heroku puts your apps hosted for free to sleep after 30 minutes of inactivity but Discords continuous HTTP requests keeps the bot alive indefinitely.
Prerequisites
Have a file named
Procfile
(with no trailing .txt or anything, justProcfile
) added to your main folder, i.e with theindex.js
file.
Inside the
Procfile
copy paste thisWorker: node index.js
Heroku uses a worker dyno to run your
index.js
file
If you have you index.js
file named as bot.js
or anything like that change the Worker
accordingly
Important steps before you upload your code to Github
- In your
index.js
folder you may have abot.login("<TOKEN>")
remove that, including the quotes and replace it withprocess.env.TOKEN
- Same with the other tokens you may have. For example if you are using the Tenor API their token should be replaced with
process.env.TENOR
- While uploading the code to Github you can keep it private or public, it doesn't matter. If you wanna show the world your code keep it public if not keep it private
Your process.env
variable can have anything after that, but it needs to be different from the other environment variables
Hosting
-
Create an account on Heroku
This should keep you bot up for 550 hours i.e approximately 23 days per month. To keep it for more link your credit card (they don't charge you) and get 450 more hours per month which is more than enough for a month.
Psst: You can create more than one account on Heroku if you have 2 mails and link both the accounts to the same Github account. So your bot stays up forever.
End note: You can put your Heroku app (the bot in this case) on maintenance mode if you aren't using it. It saves your hours per month.