0

I've been trying to create a Discord bot that posts reminders at 9:00 AM and 9:00 PM everyday from March 22, 2020 to April 27, 2020.

The scheduling process is where I initially got stuck. I took 2 approaches: 1. Doing it myself, using a 12hr long setInterval(), when I did that, i got an error stating that the progam failed to bind to a PORT within 60 seconds.

  1. Using the node.js cron library https://github.com/kelektiv/node-cron. But in this case the code itself didn't work the way I'd expect


const Discord = require('discord.js');
const cron = require('cron')
const client = new Discord.Client();

const dolChannelID = '<a working channel's id>'
let dolChannel = null

const msgs = {
    'morning': 'Morning msg',
    'evening': 'Evening msg',
    'finale': 'Final msg before ending'
}
const startTime = new Date('March 22, 2020 9:38:00')
const lastDate = new Date('April 27, 2020 21:00:00')

// --------------------------------------------------

client.on('ready', () => {

    console.log('we\'re up and running!')

    client.channels.fetch(dolChannelID)
    .then(channel => {
        dolChannel = channel
        dolChannel.send('Bot\'s working')
    })
    .then(() => {
        let execJob = new cron.CronJob('50 9,21 * * *', function() {
            let rn = new Date()
            console.log('time', rn)
            // IDEALLY HERE I'D EXPECT TO GET A CONSOLE LOG TELLING ME THE TIME twice a day, 
            // starting at 9:50 AM, but that didn't happen
            // ALTHOUGH, when my cron time expression: '* * * * * *', then things worked somehow 
            //i.e. I got an console.log every sec.


        }, null, true, 'Asia/Kolkata')
        execJob.start()
    })
    .catch((err) => {
        console.log('error \n \n', err)
    })
})


client.login(<my secret>);


I would appreciate any help. I can't seem to figure out

  • 1
    If you are using Heroku make sure to use the worker instance and not the web one. – PLASMA chicken Mar 22 '20 at 12:54
  • Thank you so much! I had actually found a solution here https://stackoverflow.com/questions/51984638/discord-app-error-r10-when-deploying-with-heroku/51985448. Forgot to remove the question. Should I just edit the question instead, and give the link I sent above? – Rahul Tandon Mar 23 '20 at 14:08
  • Does this answer your question? [Discord app error R10 when deploying with Heroku](https://stackoverflow.com/questions/51984638/discord-app-error-r10-when-deploying-with-heroku) – PLASMA chicken Mar 23 '20 at 23:46
  • Flagged it as Duplicate – PLASMA chicken Mar 23 '20 at 23:47

0 Answers0