This is an example of how you can accomplish to make a scheduled message using Discord Bot
and node-cron
Cron
is one of the popular utility that provide some form of job scheduler or automation code
Tech stack used in this example:
- express (server framework)
- axios (HTTP client)
- node-cron (Cron-job scheduling)
- dotenv (environment variable)
In this example, we are using Discord Developer Portal documentation which allow us to create Discord Bot & Application along with its permission (wether to just sending message or change user role) with ease. Just follow along the official documentation intro.
Then, we use axios as a HTTP client to make a request to Discord Bot endpoint (make sure that the Bot is added to your server).
Read more:
Working with node-cron
or any package that utilized any form of Cron Job is relatively easy, if we know the standarized unix-cron string format
.
The standard time fields is going to be like this:
'* * * * *'
each star '*'
represent a Minute, Hour, Day of the Month, Month, and Day of the Week respectively, and we can change it to suit our needs.
Read more:
- IBM's Unix Cron format docs
- Configure Cron Job schedule
- Crontab.guru: a simple cron schedule expression editor
Hope this helps!