1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
import { BotCommand, clientSendAndPermCheck, colors, format, type CommandMessage, type SlashMessage } from '#lib';
import { EmbedBuilder, PermissionFlagsBits, type Message } from 'discord.js';
export default class PingCommand extends BotCommand {
public constructor() {
super('ping', {
aliases: ['ping'],
category: 'info',
description: 'Gets the latency of the bot',
usage: ['ping'],
examples: ['ping'],
slash: true,
clientPermissions: (m) => clientSendAndPermCheck(m, [PermissionFlagsBits.EmbedLinks], true),
userPermissions: []
});
}
public override async exec(message: CommandMessage) {
const timestamp1 = message.editedTimestamp ? message.editedTimestamp : message.createdTimestamp;
const msg = await message.util.reply('Pong!');
const timestamp2 = msg.editedTimestamp ? msg.editedTimestamp : msg.createdTimestamp;
void this.command(message, timestamp2 - timestamp1);
}
public override async execSlash(message: SlashMessage) {
const timestamp1 = message.createdTimestamp;
const msg = (await message.util.reply({ content: 'Pong!', fetchReply: true })) as Message;
const timestamp2 = msg.editedTimestamp ? msg.editedTimestamp : msg.createdTimestamp;
void this.command(message, timestamp2 - timestamp1);
}
private command(message: CommandMessage | SlashMessage, msgLatency: number) {
const botLatency = format.codeBlock(`${Math.round(msgLatency)}ms`);
const apiLatency = format.codeBlock(`${Math.round(message.client.ws.ping)}ms`);
const embed = new EmbedBuilder()
.setTitle('Pong! 🏓')
.addFields(
{ name: 'Bot Latency', value: botLatency, inline: true },
{ name: 'API Latency', value: apiLatency, inline: true }
)
.setFooter({ text: message.author.username, iconURL: message.author.displayAvatarURL() })
.setColor(colors.default)
.setTimestamp();
return message.util.reply({
content: null,
embeds: [embed]
});
}
}
|