From 9016da2f7344c7128c29257336162e40500fe4f8 Mon Sep 17 00:00:00 2001 From: Isaac Date: Fri, 19 Feb 2021 23:39:59 +0000 Subject: [PATCH] moved --- src/listeners/interaction.js | 21 ++++++++------------- src/modules/commands/manager.js | 21 ++++++++++++--------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/src/listeners/interaction.js b/src/listeners/interaction.js index 6913507..eaa108b 100644 --- a/src/listeners/interaction.js +++ b/src/listeners/interaction.js @@ -3,26 +3,21 @@ module.exports = { raw: true, execute: async (client, interaction) => { - if (interaction.type === 1) { + switch (interaction.type) { + case 1: client.log.debug('Received interaction ping, responding with pong'); - return await client.api.interactions(interaction.id, interaction.token).callback.post({ + await client.api.interactions(interaction.id, interaction.token).callback.post({ data: { type: 1, } }); + break; + case 2: + client.commands.execute(interaction.data.name, interaction); + break; } - const cmd = interaction.data.name; - - if (!client.commands.commands.has(cmd)) - return client.log.warn(`[COMMANDS] Received "${cmd}" command invocation, but the command manager does not have a "${cmd}" command`); - - try { - client.commands.execute(cmd, interaction); - } catch (e) { - client.log.warn(`[COMMANDS] An error occurred whilst executed the ${cmd} command`); - client.log.error(e); - } + } }; \ No newline at end of file diff --git a/src/modules/commands/manager.js b/src/modules/commands/manager.js index fa134ae..e24068d 100644 --- a/src/modules/commands/manager.js +++ b/src/modules/commands/manager.js @@ -144,7 +144,7 @@ module.exports = class CommandManager { */ async execute(cmd_name, interaction) { if (!this.commands.has(cmd_name)) - throw new Error(`Unregistered command: "${cmd_name}"`); + throw new Error(`Received "${cmd_name}" command invocation, but the command manager does not have a "${cmd_name}" command`); let args = {}; if (interaction.data.options) @@ -168,15 +168,18 @@ module.exports = class CommandManager { let msg = `❌ You do not have the permissions required to use this command:\n${perms}`; return await cmd.sendResponse(interaction, msg, true); } + + try { + await cmd.deferResponse(interaction, true); + this.client.log.commands(`Executing "${cmd_name}" command (invoked by ${data.member.user.tag})`); + let res = await cmd.execute(data, interaction); // run the command + if (typeof res === 'object' || typeof res === 'string') + cmd.sendResponse(interaction, res, res.secret); + } catch (e) { + this.client.log.warn(`[COMMANDS] An error occurred whilst executed the ${cmd} command`); + this.client.log.error(e); + } - await cmd.deferResponse(interaction, true); - - this.client.log.commands(`Executing "${cmd_name}" command (invoked by ${data.member.user.tag})`); - - let res = await cmd.execute(data, interaction); // run the command - - if (typeof res === 'object' || typeof res === 'string') - cmd.sendResponse(interaction, res, res.secret); } }; \ No newline at end of file