简体   繁体   中英

ping command on discord.js

I'm making a command that would calculate my bot's ping, but I have a problem. It's telling me that msg is not defined. How am i supposed to define it? 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((message) => {
   const ping = msg.createdTimestamp - message.createdTimestamp;
   message.edit(`${ping} ms`);
  });
 },
};

Your message is defined as message , not msg . Just edit this line:

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

The code itself was correct, you just passed the wrong name as a parameter. Use msg instead of message .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM