110 lines
2.2 KiB
JavaScript
110 lines
2.2 KiB
JavaScript
const Discord = require('discord.js');
|
|
const fs = require('fs');
|
|
|
|
const {
|
|
token,
|
|
guildId,
|
|
} = require('./config.json');
|
|
|
|
const client = new Discord.Client({
|
|
intents: ['GUILDS', 'GUILD_MESSAGES', 'GUILD_MESSAGE_REACTIONS'],
|
|
});
|
|
const clientCommands = new Discord.Collection();
|
|
|
|
async function registryCommands() {
|
|
|
|
const owner = (await client.application.fetch()).owner;
|
|
|
|
module.exports = {
|
|
owner,
|
|
};
|
|
|
|
console.time('Duration');
|
|
|
|
const guildCommands = client.guilds.cache.get(guildId).commands;
|
|
|
|
const commandsData = [];
|
|
|
|
const commandFolders = fs.readdirSync('./commands');
|
|
|
|
for (const folder of commandFolders) {
|
|
|
|
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
|
|
|
|
for (const file of commandFiles) {
|
|
|
|
const cmd = require(`./commands/${folder}/${file}`);
|
|
|
|
clientCommands.set(cmd.name, cmd);
|
|
|
|
commandsData.push(cmd);
|
|
|
|
}
|
|
}
|
|
|
|
await guildCommands.set(commandsData);
|
|
|
|
for (const folder of commandFolders) {
|
|
|
|
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
|
|
|
|
for (const file of commandFiles) {
|
|
|
|
const cmd = require(`./commands/${folder}/${file}`);
|
|
|
|
const cmdId = (await guildCommands.fetch()).find(command => command.name === cmd.name).id;
|
|
|
|
clientCommands.set(cmd.name, {
|
|
id: cmdId,
|
|
data: cmd,
|
|
});
|
|
|
|
(await guildCommands.fetch(cmdId)).permissions.set({
|
|
id: cmdId,
|
|
permissions: cmd.permissions,
|
|
});
|
|
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
clientCommands,
|
|
guildCommands,
|
|
};
|
|
|
|
console.group('\nCOMMANDS REGISTERED');
|
|
|
|
console.timeEnd('Duration');
|
|
console.log('Commands table:');
|
|
console.table(clientCommands);
|
|
|
|
console.groupEnd();
|
|
|
|
}
|
|
|
|
client.on('ready', async () => {
|
|
|
|
registryCommands();
|
|
|
|
console.log('-- BOT READY --');
|
|
|
|
});
|
|
|
|
client.login(token);
|
|
|
|
client.on('interactionCreate', async interaction => {
|
|
|
|
if (!interaction.isCommand() || !clientCommands.has(interaction.commandName)) return;
|
|
|
|
try {
|
|
await clientCommands.get(interaction.commandName).data.execute(interaction);
|
|
}
|
|
catch (error) {
|
|
console.error(error);
|
|
await interaction.reply({
|
|
content: `A error occur while trying to execute \`${interaction.commandName}\`\n\`\`\`${error}\`\`\``,
|
|
ephemeral: true,
|
|
});
|
|
}
|
|
|
|
}); |