Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
TypeError: cron.CronJob is not a constructor

I'm trying to make the bot writing messages every day. I installed npm install discord.js and npm install --save node-cron.

const { Client, Intents, GuildMember } = require('discord.js');
var cron = require('node-cron');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, 
Intents.FLAGS.GUILD_MESSAGES] });
const TOKEN = '#';

client.once('ready', () => {
console.log("I am ready");
});

let job = new cron.CronJob('30 2 * * *', () => {
client.channels.cache.get('#').send("Hello!!")
})
job.start();
client.login(TOKEN)

And terminal says

 "let job = new cron.CronJob('30 2 * * *', () => {
      ^
 TypeError: cron.CronJob is not a constructor"
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As @Zsolt Meszaros has mentioned, you're mixing cron and node-cron. If you want to use node-cron, your scheduling should look something like this:

cron.schedule('* * * * *', () => {
  console.log('running a task every minute');
});

Applied into your code it would look something like this:

const { Client, Intents, GuildMember } = require("discord.js");
const cron = require("node-cron");
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});
const TOKEN = "#";

client.once("ready", () => {
  console.log("I am ready");
});

let job = cron.schedule("30 2 * * *", () => {
  client.channels.cache.get("#").send("Hello!!");
});

client.login(TOKEN);

NOTE

You do not need to use task.start() unless you provide the scheduled: false parameter into the task.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!