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

189
Views
TypeError: cron.CronJob no es un constructor

Estoy tratando de hacer que el bot escriba mensajes todos los días. Instalé npm install discord.js y 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)

Y la terminal dice

 "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

Como mencionó @Zsolt Meszaros, está mezclando cron y node-cron . Si desea usar node-cron , su programación debería verse así:

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

Aplicado a su código se vería algo como esto:

 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);

NOTA

No necesita usar task.start() a menos que proporcione el parámetro scheduled: false en la tarea.

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!