Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

760
Visualizações
Send a message at a specific timestamp in Discord js

I'm new to discord js and trying to make my bot send a message at a specific time (set via timestamp).

client.on('ready', function(e) 
{
console.log(`Logged in as ${client.user.tag}!`)

let scheduledMessage = new cron.CronJob('0 10 15 * * *', () => {
    const guild = client.guilds.cache.get('ID');
    const channel = client.channels.cache.get('ID');

    const exampleEmbed = new MessageEmbed()
    .setColor('#ebdc05')
    .setTitle('Another ten minutes')
    channel.send({ embeds: [exampleEmbed] });
});

scheduledMessage.start() 
});

I found this method that sends a message at 15:10:00. My problem is that I would need the bot to send the message every 31 hours.

I also found the method to write '0 0 */31 * * *' instead of '0 10 15 * * *'. And that works, every 31 hours a message would be sent, but I'm afraid my bot sometimes could send the message a bit after the 31-hour mark and just add up seconds and minutes after time, that at some point it sends the message at like 15:12:00 or sth.

So I came up with the idea to just make a timestamp, and add the time to always have the 31 hours, then let the bot send the message at the exact timestamp. Sadly, I found nothing to that problem.

Is that even possible?


Edit: The timestamp variant would be useful because I can subtract and add time to that very easily and also show it in an embed.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The point of the cron library you're using is that you can explicitly tell it the minutes and seconds—in your case, 0.

It won't accumulate errors. Unless it's very broken, the cron library will do the "figure out the next timestamp" stuff for you.

The cron string 0 0 */31 * * * means "Every 31 hours, when the time looks like XX:00:00". So it will never run at 15:12:00—or 15:10:00 for that matter. You've said "run at this exact minute and second", so it will.

Disclaimer: I tried to read the code of https://github.com/kelektiv/node-cron to confirm this myself, but it's pretty convoluted. https://github.com/node-cron/node-cron/tree/master/src was easier to read and it definitely is checking the timestamp every second.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda