How to use cron-job.org to run your bots hosted on Glitch
One downside of using Glitch to host your bots is that your bot will automatically go to sleep after 5 minutes, unless your app continues to receive external traffic.
This doesn’t work well for bots, which need to run constantly, and the solution suggested by the Glitch team is to automatically ping your app to wake it up. This will restart your app, allowing your bot to do its thing before the app is shut down. There’s a few free websites you can use to automate this process, for example cron-job.org or uptimerobot.com.
In this tutorial I will show you how to use cron-job.org.
(As a side note, if you’re not familiar with the term cron, check this quick explanation.)
If you’re using one of the Botwiki bot starter projects on Glitch, you will be asked to add a
BOT_ENDPOINT variable to your
.env file. The value can be anything, for example
It should be somewhat unique and hard to guess, so that someone else can’t run your bot and cause you to go over the API rate limit.
Once you set your
BOT_ENDPOINT, use the Show button next to your apps name, copy the URL of your project, and append the value of
BOT_ENDPOINT at the end.
For example, if your project’s URL is this:
And you set your endpoint to
12345, your endpoint URL will be:
Now, go to cron-job.org and sign up for an account. Head to the “Cronjobs” section and add a new cronjob.
Click “User defined” under “Schedule”. Here, select all the options under Days of months, Days of week, Months. Under Minutes, select 0. And under Hour, select on which hour your bot will post.
For example, if you want to post every 6 hours, select the options 0, 6, 12, and 18.
Hit the “Create cronjob” button at the bottom of the page, and you’re all set!