在discord.js上执行ping命令

时间:2020-09-03 15:09:21

标签: javascript node.js discord discord.js

我正在执行一个可以计算机器人ping的命令,但是我遇到了问题。告诉我msg未定义。我应该如何定义它?这是我的代码:

module.exports = {
 name: 'ping',
 description: "shows the bot/'s ping",
 execute(message, args) {
  message.channel.send('`ping is being calculated...`').then((message) => {
   const ping = msg.createdTimestamp - message.createdTimestamp;
   message.edit(`${ping} ms`);
  });
 },
};

2 个答案:

答案 0 :(得分:1)

您的message被定义为message,而不是msg。只需编辑此行:

.then((msg) => {
 const ping = msg.createdTimestamp - message.createdTimestamp;
 msg.edit(ping + 'ms');
});

答案 1 :(得分:0)

代码本身是正确的,您只是传递了错误的名称作为参数。使用msg代替message

message.channel.send("ping is being calculated...").then((msg) => {
  const ping = msg.createdTimestamp - message.createdTimestamp;
  message.edit(`${ping} ms`);
});