From 5a750c99512a8675eb25c45538c9356d3a72d5bd Mon Sep 17 00:00:00 2001 From: loicbersier Date: Tue, 9 Oct 2018 16:31:23 +0200 Subject: [PATCH] Changed ping a little --- commands/utility/ping.js | 34 ++++++++++++++++++++++++++++++++++ index.js | 3 ++- 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 commands/utility/ping.js diff --git a/commands/utility/ping.js b/commands/utility/ping.js new file mode 100644 index 00000000..4cffe9f4 --- /dev/null +++ b/commands/utility/ping.js @@ -0,0 +1,34 @@ +const { oneLine } = require('common-tags'); +const { Command } = require('discord.js-commando'); + +module.exports = class PingCommand extends Command { + constructor(client) { + super(client, { + name: 'ping', + group: 'util', + memberName: 'ping', + description: 'Checks the bot\'s ping to the Discord server.', + throttling: { + usages: 5, + duration: 10 + } + }); + } + + async run(msg) { + if(!msg.editable) { + const pingMsg = await msg.say('Pinging...'); + return pingMsg.edit(oneLine` + ${msg.channel.type !== 'dm' ? `${msg.author},` : ''} + <:ping:499226870047571978> Pong! The message round-trip took **${pingMsg.createdTimestamp - msg.createdTimestamp}**ms. + ${this.client.ping ? `The heartbeat ping is **${Math.round(this.client.ping)}**ms.` : ''} + `); + } else { + await msg.edit('Pinging...'); + return msg.edit(oneLine` + Pong! The message round-trip took **${msg.editedTimestamp - msg.createdTimestamp}**ms. + ${this.client.ping ? `The heartbeat ping is **${Math.round(this.client.ping)}**ms.` : ''} + `); + } + } +}; diff --git a/index.js b/index.js index b458d525..66d32415 100644 --- a/index.js +++ b/index.js @@ -25,7 +25,8 @@ client.registry ]) .registerDefaultGroups() .registerDefaultCommands({ - help: false + help: false, + ping: false }) .registerCommandsIn(path.join(__dirname, 'commands')); // Ready messages