1+ // Know more about how ping is calculated ~ https://discordjs.guide/popular-topics/faq.html#how-do-i-check-the-bot-s-ping
2+
13const { 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
39module . 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} ;
0 commit comments