Skip to content

Commit f2f23ae

Browse files
authored
feat: return latency and roundtrip duration in ping command (#56)
1 parent 0b0fe14 commit f2f23ae

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/commands/ping.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,14 @@ export const pingCommand = createCommand({
66
description: 'Replies with Pong!',
77
},
88
execute: async (interaction) => {
9-
const user = interaction.user;
10-
await interaction.reply(`<@${user.id}> Pong!`);
9+
const sent = await interaction.reply({ content: 'pinging...', withResponse: true });
10+
const message = sent.resource?.message;
11+
if (!message) {
12+
await interaction.editReply('Failed to send ping message.');
13+
return;
14+
}
15+
const roundTrip = message.createdTimestamp - interaction.createdTimestamp;
16+
const apiLatency = interaction.client.ws.ping;
17+
await interaction.editReply(`latency: ${apiLatency}ms | Roundtrip: ${roundTrip}ms`);
1118
},
1219
});

0 commit comments

Comments
 (0)