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
JavaScript
x
2
1
message.channel.send("Beep").then((sentMessage) => sentMessage.edit("Boop!"))
2
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:
JavaScript141setTimeout(function[, delay, arg1, arg2, ]);
2setTimeout(function[, delay]);
3setTimeout(code[, delay]);
4
Note that the delay is in ms. (3000ms = 3 seconds)
JavaScript
1
6
1
message.channel.send('Beep!').then(sentMessage => {
2
setTimeout(() => {
3
sentMessage.edit('Boop!')
4
}, 3000);
5
})
6