CodeNewbie Community 🌱

Alica V.
Alica V.

Posted on

Building a reminder system

Hello all! I am interested in developing a reminder Discord bot. Existing bots with this function have a premium to pay for re-occuring reminders, which is why I would like to develop my own.


Project basics

In short, I am interested in building a reminder bot capable of taking input /remindme [future time] [message], and sending a reminder to the user. I am unsure how to implement the javascript logic for reminders. I'm seeking resources to learn!

Other examples of uses:
/remindme every 2 weeks on Sunday to do laundry -> without time specified, it will assume 12PM on Sunday.
/remindme tomorrow at 2PM to wrap presents
/remindme December 12th at 7AM to send mail


What I have tried

I have followed this this article as a tutorial to get set up with the basics, using Javascript. Now I'm planning out the functionality. After looking at a few Github repos with similar projects, I'm having trouble understanding how to implement some of these functions.

So far, I understand that I will need to interpret user input into some sort of datetime object.


My questions

  • How does a program "wait" for an amount of time before doing something..?

  • If I need to shut down the bot for maintenance, how can I ensure existing reminders can still be delivered once the bot is back up? Will I need a database to store reminder information?

  • What is an effective way to create a reminder system in Javascript, if a reminder is set weeks apart? My first thought was to create a countdown per reminder, but now I think I should check the given reminder date against the current date to avoid long countdowns. I am not sure what is a reasonable approach.


Any advice or resources is appreciated! Thanks

Top comments (2)

Collapse
 
terabytetiger profile image
Tyler V. (he/him) • Edited

Disclaimer: I have not actually built anything quite like this, but can provide my ideas about how I would start to go about it

If I need to shut down the bot for maintenance, how can I ensure existing reminders can still be delivered once the bot is back up? Will I need a database to store reminder information?

I'll start with this one because it's the part of my answer I'm most confident in 😅

Yes, you'll have to store the information somewhere if you want it to come back after restarting the bot.


How does a program "wait" for an amount of time before doing something..?

In Javascript this is a surprisingly non-trivial task to accomplish. Wes Bos has a small npm package that does this (although idk if his is built to run for days apart) that might be helpful to look at: github.com/wesbos/waait

As far as I know, the go-to thing for scheduling repeated tasks is called Cron. I also find this website very helpful for understanding the format for scheduling Cron jobs.


My best guess for what to do would be create your records with something like:

{
  "name": "Do the Laundry",
  "reminderTime": 1670597975,
  "repeat": 0 // how many time units to add to reminder time once sent to user
  // If ^ 0 or -1, then don't repeat, whichever flag you want to use
}
Enter fullscreen mode Exit fullscreen mode

(Time format from epochconverter.com/)

Hope this helps set you in the right direction - let me know if any of that was confusing! 😅

Collapse
 
larrymartin1job profile image
Larry Martin

Exciting project! Consider using setTimeout for delayed execution in JavaScript. To persist reminders during bot shutdowns, a database like SQLite or MongoDB could be handy. For reminders weeks apart, comparing reminder dates to the current date is a practical approach. Good luck with your Discord reminder bot development!
Hazard Tree Removal in Fresno CA