不和谐ping报告为NaN

时间:2020-09-16 15:53:33

标签: javascript discord.js

我正在制造Discord Bot,目前正在使用高级命令处理程序。我做了一个ping命令,完成后,API ping显示NaN(不是数字),这很令人困惑,因为当我使用基本命令处理程序时,它显示的是实际数字。没有错误消息或任何可清除的内容。这是我的代码:

const Discord = require('discord.js');
const client = new Discord.Client();
const embed = new Discord.MessageEmbed();

module.exports = {
 name: 'ping',
 description: 'check ping latency',
 execute(message, args) {
  //executes command

  if (message.member.hasPermission('MANAGE_NICKNAMES')) {
   //checks if author has permission

   const ping = Date.now() - message.createdTimestamp + ' ms'; //calculates dates

   embed //new embed
    .setTitle('Bot Latency:')
    .setDescription(`${Date.now() - message.createdTimestamp} ms`) //bot latency
    .addField('API Latency', `${Math.round(client.ws.ping)}ms`) //here is the problem
    .setFooter('For more details, visit discorddown')
    .setColor(0x008080);
   message.channel.send(embed);
   message.delete({
    timeout: 1000,
   });
  } else {
   message.delete({
    timeout: 1000,
   });
  }
 },
};

1 个答案:

答案 0 :(得分:0)

改为使用此

module.exports = {
commands: ['ping'],
minArgs: 0,
maxArgs: 0,
callback: async(message, arguments, text) => {
    const Discord = require('discord.js');
    //const client = new Discord.Client();
    const msg = await message.channel.send("Pinging...");
    const Embed = new Discord.MessageEmbed()
      .setTitle("Pong!")
      .setAuthor(`${message.author.username}` , message.author.displayAvatarURL())
      .setDescription(
        `⌛ Latency is ${Math.floor(
          msg.createdTimestamp - message.createdTimestamp
        )}ms\n⏲️ API Ping is ${Math.round(message.client.ws.ping)}`
      )
      .setColor('#fb644c');
    msg.edit(Embed);
    msg.edit("\u200b");
},  }