Skip to content
Advertisement

discord.js Editing a message and sleeping

So I am very new to discord.js and wanted to know how I can edit a message and then sleep and then edit the message again so it doesn’t cause extremely fast edits. I found this code and couldn’t figure out what to do

message.channel.send("Beep").then((sentMessage) => sentMessage.edit("Boop!"))

Advertisement

Answer

As suggested by LercDsgn in the comments, you can use setTimeout to edit the message after a certain amount of time.

setTimeout syntax:

setTimeout(function[, delay, arg1, arg2, ...]);
setTimeout(function[, delay]);
setTimeout(code[, delay]);

Note that the delay is in ms. (3000ms = 3 seconds)


message.channel.send('Beep!').then(sentMessage => {
    setTimeout(() => {
        sentMessage.edit('Boop!')
    }, 3000);
})
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement