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

215
Visualizações
How do I add a delay between sending messages discord.js

Here is the code:

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

client.on("message", function(message) {
message.reply('my message');
})

client.login('client login')

after the message is replied I want there to be a 5 minute delay before it can reply again BUT not reply to any messages sent before then. Here is pretty much what I want: Me: hi Bot: my message Me (2 minutes later): hi again Bot: (Sends nothing) 5 minutes later: Me: Hello once again Bot: my message

(Sorry for so much stuff)

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

0

Well, I have two solutions for you.

1# Wait for some time then execute a piece of code

You can use setTimeout(), it's a javascript function who only needs two arguments. The first one is the function who's going to get executed after a certain timeout and the second one is how much milliseconds does you code need to wait before doing that function.

message.channel.send('Hi!')
setTimeout(function(){
message.channel.send('Hi again.. !')
},1000 * 10) // 1000 milliseconds multiplied by 10, therefore 10 second.

2# Wait for some time then execute the rest of the code

This one is pretty similar to the one before but this time you won't put your code on a function. You can just create a function like so :

let sleep = async (ms) => await new Promise(r => setTimeout(r,ms));

And here you have a sleep function, it will freeze your current code for x milliseconds then continue as if nothing happens,

let sleep = async (ms) => await new Promise(r => setTimeout(r,ms));
message.channel.send('Going to sleep!')
await sleep(2000)
message.channel.send("I'm awake!!")
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