diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-05-27 17:15:53 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-05-27 17:15:53 -0400 |
commit | 705cead579a79d6ee86dd2e5edfcea2344bea6ce (patch) | |
tree | 3adf8875de96e84506d7b650cdc50d358a861d5c /src/commands/info/ping.ts | |
parent | 2c74ebf6651ccdc78e9fa5799c7887fe52b1ac2d (diff) | |
parent | 1546da359646b89f13d17784eb7653a52ca61efd (diff) | |
download | tanzanite-705cead579a79d6ee86dd2e5edfcea2344bea6ce.tar.gz tanzanite-705cead579a79d6ee86dd2e5edfcea2344bea6ce.tar.bz2 tanzanite-705cead579a79d6ee86dd2e5edfcea2344bea6ce.zip |
Merge branch 'rewrite' of https://github.com/NotEnoughUpdates/mb-bot-ts into rewrite
Diffstat (limited to 'src/commands/info/ping.ts')
-rw-r--r-- | src/commands/info/ping.ts | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/commands/info/ping.ts b/src/commands/info/ping.ts new file mode 100644 index 0000000..e0bbfc7 --- /dev/null +++ b/src/commands/info/ping.ts @@ -0,0 +1,69 @@ +import { CommandInteraction } from 'discord.js'; +import { Message } from 'discord.js'; +import { MessageEmbed } from 'discord.js'; +import { BushCommand } from '../../lib/extensions/BushCommand'; + +export default class PingCommand extends BushCommand { + constructor() { + super('ping', { + aliases: ['ping'], + category: 'info', + description: { + content: 'Gets the latency of the bot', + usage: 'ping', + examples: ['ping'] + } + }); + } + + public async exec(message: Message): Promise<void> { + const sentMessage = await message.util.send('Pong!'); + const timestamp: number = message.editedTimestamp + ? message.editedTimestamp + : message.createdTimestamp; + const botLatency = `\`\`\`\n ${Math.floor( + sentMessage.createdTimestamp - timestamp + )}ms \`\`\``; + const apiLatency = `\`\`\`\n ${Math.round( + message.client.ws.ping + )}ms \`\`\``; + const embed = new MessageEmbed() + .setTitle('Pong! 🏓') + .addField('Bot Latency', botLatency, true) + .addField('API Latency', apiLatency, true) + .setFooter( + message.author.username, + message.author.displayAvatarURL({ dynamic: true }) + ) + .setTimestamp(); + await sentMessage.edit({ + content: null, + embed + }); + } + + public async execSlash(message: CommandInteraction): Promise<void> { + const timestamp1 = message.createdTimestamp; + await message.reply('Pong!'); + const timestamp2 = await message + .fetchReply() + .then((m) => (m as Message).createdTimestamp); + const botLatency = `\`\`\`\n ${Math.floor( + timestamp2 - timestamp1 + )}ms \`\`\``; + const apiLatency = `\`\`\`\n ${Math.round(this.client.ws.ping)}ms \`\`\``; + const embed = new MessageEmbed() + .setTitle('Pong! 🏓') + .addField('Bot Latency', botLatency, true) + .addField('API Latency', apiLatency, true) + .setFooter( + message.user.username, + message.user.displayAvatarURL({ dynamic: true }) + ) + .setTimestamp(); + await message.editReply({ + content: null, + embeds: [embed] + }); + } +} |