How i can do a ping command like this:
alternatively, I run a code server that you can join just tag me if thats easier for you and i will help you as soon as i can. I assume you want someone to give u the code. Not help u write it yourself correct?
Hey @ControlCit1,
The ping command is based on the difference in the time at which the message was posted and the timestamp of the message. This is generally how it works.
var ping = Date.now() - message.createdTimestamp + " ms";
To make this into a command, just wrap it up like this:
if (message.content.startsWith(prefix + "ping")) {
var ping = Date.now() - message.createdTimestamp + " ms";
message.channel.sendMessage("Your ping is `" + `${Date.now() - message.createdTimestamp}` + " ms`");
}
Replace prefix
with the prefix of your bot.
Hope this helps!
people actually do it like that still? I would be lost without a command handler
Itu membuat bot tidak meresponds
It would be smarter to use the ping variable
if (message.content.startsWith(prefix + "ping")) {
var ping = Date.now() - message.createdTimestamp + " ms";
message.channel.sendMessage("Your ping is `" + `${ping}` + " ms`");
}
It would be smart to do msg.channel.send(“Your ping is " +
${ping} + "
”); to prevent two “ms”
Technically it’s not their ping, it’s the bot’s ping to discord, not the opposite. And you should also use client.ws.ping
to get the ping.
It’d be easier to use template literals
same thing just neater i guess
if (message.content.startsWith(`${prefix} ping`)) {
var ping = `${Date.now() - message.createdTimestamp} ms`;
message.channel.sendMessage(`Your ping is ${ping}`);
}
cleaner version is
if (message.content.startsWith(prefix + "ping")) {
message.channel.sendMessage(`Your ping is \`${Date.now() - message.createdTimestamp} ms\``);
}
Even cleaner
if (message.content.startsWith(`${prefix}ping`))
message.channel.sendMessage(`Your ping is \`${Date.now() - message.createdTimestamp}ms\``);
even cleaner
if (message.content.startsWith(`${prefix}ping`))
msg.reply(`Your ping is \`${Date.now() - msg.createdTimestamp} ms\``);
SyntaxError, msg
is undefined.
Can’t we just do this?
msg.reply(`Your ping is ${Date.now() - msg.createdTimestamp} ms`);
Also why is everyone trying to clean it up?
You can do
message.channel.send(`${message.author}`, new Discord.MessageEmbed() .setTitle(`🏓**Pong** `) .setDescription(`**Latency:**${Date.now() - message.createdTimestamp}ms`) .setColor(‘BLUE’));
It worked for my and it’s like the screenshot you send
How do you do this for a slash command?