Added command executing system.

Rebuild, again, the command handling system, now to support the event handling.

Also added more organized console logs.
This commit is contained in:
Guz
2021-08-26 16:59:00 -03:00
parent 01c884d97b
commit 671052f1c1
5 changed files with 121 additions and 109 deletions

View File

@@ -1,28 +1,34 @@
const { devGuildId } = require('../../config.json');
const { commands, permissions } = require('../../index');
const config = require('../../config.json');
const { commands } = require('../../index');
module.exports = {
name: 'ready',
async execute(client) {
console.log('bot ready!');
console.log(await commands);
console.log(await permissions);
await client.application?.fetch();
for (let i = 0; i < commands.length; i++) {
for (const command of commands) {
const command = (await client.guilds.cache.get(devGuildId)?.commands.fetch()).find(c => c.name === commands[i].name);
const clientCommand = (await client.guilds.cache.get(config.devGuildId)?.commands.fetch()).find(c => c.name === command.data.name);
console.log(command.id);
await clientCommand.permissions.set({ id: clientCommand.id, permissions: command.permissions });
const permission = permissions[i];
console.log(permission);
await command.permissions.set({ id: command.id, permissions: permission });
command.id = clientCommand.id;
command.name = clientCommand.name;
}
console.log('Guild commands totally registered');
console.log('\nGuild Commands:');
console.table(commands);
console.log('\nBot configurations');
console.table({
'Owner Id': config.ownerId,
'Development Guild Id': config.devGuildId,
'Client Id': config.clientId,
});
console.log('\n\n-- BOT READY --\n\n');
},
};

View File

@@ -1,22 +1,34 @@
const { commands } = require('../../index');
module.exports = {
name: 'interactionCreate',
async execute(interaction, client) {
if (!interaction.isCommand() || !client.commands.has(interaction.commandName)) return;
if(interaction.isCommand()) {
const command = client.commands.get(interaction.commandName);
console.log(`\nCommand ${interaction.commandName} executing ----------------\n`);
if (!command) return;
const command = commands.find(c => c.data.name === interaction.commandName);
console.log('\nCommand data:\n');
console.log(command);
console.log('\nCommand console:\n');
if(!command) return;
try {
await command.execute(interaction, client);
}
catch (error) {
console.error(error);
await interaction.reply({
content: `A error occur while trying to execute the command.\n\`\`\`${error}\`\`\``,
ephemeral: true,
});
}
console.log(`\nCommand ${interaction.commandName} executed ----------------\n`);
try {
await command.execute(interaction);
}
catch (error) {
console.error(error);
await interaction.reply({
content: 'A error occur while trying to execute the command.\n```' + error + '```',
ephemeral: true,
});
}
},