UNPKG

dexare

Version:

Modular and extendable Discord bot framework

32 lines (28 loc) 986 B
import { oneLine } from 'common-tags'; import DexareClient from '../../../client'; import DexareCommand from '../command'; import CommandContext from '../context'; export default class PingCommand extends DexareCommand { constructor(client: DexareClient<any>) { super(client, { name: 'ping', description: "Checks the bot's ping and latency.", category: 'General', metadata: { examples: ['ping'] } }); this.filePath = __filename; } async run(ctx: CommandContext) { const currentPing = Array.from(this.client.bot.shards.values()) .map((shard) => shard.latency) .reduce((prev, val) => prev + val, 0); const timeBeforeMessage = Date.now(); const pingMsg = await ctx.reply('Pinging...'); await pingMsg.edit(oneLine` Pong! The message took ${(Date.now() - timeBeforeMessage).toLocaleString()}ms to be created. The heartbeat ping is ${Math.round(currentPing).toLocaleString()}ms. `); } }