From 239b864bf34e4b4520a00bb36b4de5849341504e Mon Sep 17 00:00:00 2001 From: Eartharoid Date: Sat, 4 May 2019 00:01:33 +0100 Subject: [PATCH] update command handler --- commands/help.js | 5 +++-- commands/new.js | 2 +- index.js | 13 +++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/commands/help.js b/commands/help.js index e2110c7..d37364a 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,13 +1,14 @@ const Discord = require('discord.js'); const { version } = require('../package.json'); +const config = require('../config.json'); module.exports = { name: 'help', description: 'Displays help menu', usage: '[command]', aliases: ['command', 'commands'], args: false, - cooldown: 5, - execute(message, args, config, version) { + cooldown: config.cooldown, + execute(message, args) { const client = message.client; // command starts here message.delete(); diff --git a/commands/new.js b/commands/new.js index 13c47a2..ffb151f 100644 --- a/commands/new.js +++ b/commands/new.js @@ -4,7 +4,7 @@ module.exports = { usage: '', aliases: ['ticket'], args: true, - execute(message, args, config) { + execute(message, args) { // command starts here message.delete(); const ticketChannel = "channel"; diff --git a/index.js b/index.js index ed0f86a..071fd50 100644 --- a/index.js +++ b/index.js @@ -170,8 +170,12 @@ client.on('message', message => { const [, matchedPrefix] = message.content.match(prefixRegex); const args = message.content.slice(matchedPrefix.length).trim().split(/ +/); const commandName = args.shift().toLowerCase(); - if (!client.commands.has(commandName)) return; - const command = client.commands.get(commandName); + // if (!client.commands.has(commandName)) return; + // const command = client.commands.get(commandName); + const command = client.commands.get(commandName) + || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); + + if (!command) return; if (command.args && !args.length) { let reply = `:x: **Arguments were expected but none were provided.**`; @@ -200,12 +204,13 @@ client.on('message', message => { return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`); } } - + timestamps.set(message.author.id, now); + setTimeout(() => timestamps.delete(message.author.id), cooldownAmount); try { // client.commands.get(command).execute(message, args, config); - command.execute(message, args, config); + command.execute(message, args); } catch (error) { console.error(error); message.channel.send(`:x: **Oof!** An error occured whilst executing that command.\nThe issue has been reported.`);