Skip to content Skip to sidebar Skip to footer

Discord.js Ping Command

I was trying to make a ping command for my bot here is my Code client.on('message', message => { if (message.content === '+ping') { message.channel.send(`🏓Latency is

Solution 1:

You need to use Date.now() - message.createdTimestamp to get the latency.

client.on('message', message => {
  if (message.content === '+ping') {  
    message.channel.send(`🏓Latency is ${Date.now() - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
  }
});

Solution 2:

client.on('message', message => {
  if (message.content === prefix + 'ping') {
  message.channel.send('Loading data').then (async (msg) =>{
    msg.delete()
    message.channel.send(`🏓Latency is ${msg.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
  })
  }
});

Solution 3:

I use this As My Ping Command (Sorry if I make Any Kind of Mistake, I just learned JavaScript in the last 2 Days)

module.exports={
    name:'ping',
    description: "Command ini digunakan untuk Ping",
    execute(message, args){
        message.channel.send(`🏓Latency is ${Date.now() - message.createdTimestamp}ms`);
        }
      };

Solution 4:

you need to use .then() to have m:

client.on('message', message => {
  if (message.content === '+ping') {  
message.channel.send('pinging').then(m => {
    m.edit(`🏓Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
  });
}
});

Solution 5:

you need to do

client.on('message', message => {
  if (message.content === '+ping') {  
    message.channel.send(`🏓Latency is ${Date.now() - message.createdTimestamp}ms. API Latency is ${Math.round(client.ws.ping)}ms`);
  }
});

Post a Comment for "Discord.js Ping Command"