0

I've successfully made a ping command, calculating my bot's ping. But I want it to have a delay, about 2 seconds before it sends it result.

Here's my code:

module.exports = {
    name: 'ping',
    description: "shows the bot/'s ping",
    execute(message, args) {
        message.channel.send('`ping is being calculated...`').then(msg => {
            const ping = msg.createdTimestamp - message.createdTimestamp;
            msg.channel.send('`bot\'s` ping: ' + ping + "`ms`")
        })
    }
}
Jakye
  • 6,440
  • 3
  • 19
  • 38
c.ales
  • 59
  • 1
  • 2
  • 6
  • Have you tried [`setTimeout`](https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout) ? – Seblor Sep 03 '20 at 21:34

1 Answers1

3

Using setTimeout(() => {code}, timeMs) achieves exactly that;

module.exports = {
    name: 'ping',
    description: "shows the bot/'s ping",
    execute(message, args) {
        message.channel.send('`ping is being calculated...`').then(msg => {
           setTimeout(() => {
            const ping = msg.createdTimestamp - message.createdTimestamp;
            msg.channel.send('`bot\'s` ping: ' + ping + "`ms`")
            }, 2000)
        })
    }
}
Eray Ismailov
  • 305
  • 3
  • 8