Skip to content

Commit 7cdaecf

Browse files
committed
/ping - Not as useless as it was
Displays - Bot Latency (Roundtrip message Latency) - Discord API Latency (Websocket Heratbeat) - Bot Uptime
1 parent d1370eb commit 7cdaecf

3 files changed

Lines changed: 92 additions & 116 deletions

File tree

β€Žcommands/ping.jsβ€Ž

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,38 @@
1+
// Know more about how ping is calculated ~ https://discordjs.guide/popular-topics/faq.html#how-do-i-check-the-bot-s-ping
2+
13
const { SlashCommandBuilder } = require('@discordjs/builders');
4+
const { MessageEmbed } = require('discord.js');
5+
const format = require('pretty-ms');
6+
// pretty-ms is an npm package which converts time in milliseconds to human readable format
7+
// For Eg. `format(1337000000)` will output `15d 11h 23m 20s`
28

39
module.exports = {
410
data: new SlashCommandBuilder()
511
.setName('ping')
6-
.setDescription('Replies with Pong!'),
12+
.setDescription('πŸ“Pong! Let\'s do some math!!'),
713
async execute(interaction) {
8-
await interaction.reply('Pong!');
14+
const sent = await interaction.reply({ content: 'πŸ“Ping!\nDoing MathπŸ”„', fetchReply: true });
15+
sent;
16+
await interaction.editReply({
17+
content: 'PongπŸ“!\nDone with Mathβœ…',
18+
embeds: [embed(interaction, sent)],
19+
});
920
},
21+
};
22+
23+
// EMBED CONSTRUCTOR
24+
const embed = (interaction, sent) => {
25+
return new MessageEmbed()
26+
.setColor('#15e854')
27+
.setDescription(`
28+
πŸ€– **Bot Latency** β‰ˆ ${sent.createdTimestamp - interaction.createdTimestamp} ms
29+
or Roundtrip Latency
30+
31+
βš™ **Discord API Latency** β‰ˆ ${interaction.client.ws.ping} ms
32+
or Websocket Heartbeat
33+
34+
πŸ”Ό **Uptime** β‰ˆ ${format(interaction.client.uptime, { verbose: true, secondsDecimalDigits: 0, unitCount: 2 })}
35+
36+
[This is how latencies are measured](https://discordjs.guide/popular-topics/faq.html#how-do-i-check-the-bot-s-ping)
37+
`);
1038
};

β€Žpackage-lock.jsonβ€Ž

Lines changed: 60 additions & 113 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

β€Žpackage.jsonβ€Ž

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
"discord-api-types": "^0.22.0",
2626
"discord.js": "^13.1.0",
2727
"dotenv": "^10.0.0",
28-
"express": "^4.17.1"
28+
"express": "^4.17.1",
29+
"pretty-ms": "^7.0.1"
2930
},
3031
"devDependencies": {
3132
"eslint": "^7.32.0",

0 commit comments

Comments
Β (0)