This commit is contained in:
Isaac 2021-02-19 23:39:59 +00:00
parent 4e2b7d1441
commit 9016da2f73
No known key found for this signature in database
GPG Key ID: 279D1F53391CED07
2 changed files with 20 additions and 22 deletions

View File

@ -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);
}
}
};

View File

@ -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)
@ -169,14 +169,17 @@ module.exports = class CommandManager {
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);
}
}
};