2021-08-26 16:59:00 -03:00
|
|
|
const { Client, Collection, Intents } = require('discord.js');
|
|
|
|
|
const { REST } = require('@discordjs/rest');
|
|
|
|
|
const { Routes } = require('discord-api-types/v9');
|
|
|
|
|
|
2021-08-08 09:49:22 -03:00
|
|
|
const fs = require('fs');
|
|
|
|
|
|
2021-08-27 13:28:12 -03:00
|
|
|
const console = require('./functions/meta/console');
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-17 13:36:02 -03:00
|
|
|
const client = new Client({
|
|
|
|
|
intents: [Intents.FLAGS.GUILDS],
|
|
|
|
|
});
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 20:32:30 -03:00
|
|
|
client.commands = new Collection();
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 20:32:30 -03:00
|
|
|
const commandFolders = fs.readdirSync('./commands');
|
|
|
|
|
const commands = [];
|
2021-08-26 16:59:00 -03:00
|
|
|
const commandsData = [];
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 20:32:30 -03:00
|
|
|
for (const folder of commandFolders) {
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 20:32:30 -03:00
|
|
|
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 20:32:30 -03:00
|
|
|
for (const file of commandFiles) {
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 21:05:23 -03:00
|
|
|
const command = require(`./commands/${folder}/${file}`);
|
2021-08-26 17:58:38 -03:00
|
|
|
|
|
|
|
|
if(command.properties) command.proprieties.folder = folder;
|
|
|
|
|
else command.properties = { folder: folder };
|
|
|
|
|
|
2021-08-26 16:59:00 -03:00
|
|
|
commands.push(command);
|
|
|
|
|
commandsData.push(command.data.toJSON());
|
2021-08-08 09:49:22 -03:00
|
|
|
|
|
|
|
|
}
|
2021-08-16 20:32:30 -03:00
|
|
|
}
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-17 13:36:02 -03:00
|
|
|
const rest = new REST({
|
|
|
|
|
version: '9',
|
2021-08-27 13:28:12 -03:00
|
|
|
}).setToken(process.env.TOKEN);
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-26 16:59:00 -03:00
|
|
|
module.exports = { commands, commandsData, rest };
|
|
|
|
|
|
2021-08-16 20:32:30 -03:00
|
|
|
(async () => {
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 20:32:30 -03:00
|
|
|
try {
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 20:32:30 -03:00
|
|
|
await rest.put(
|
2021-08-27 13:28:12 -03:00
|
|
|
Routes.applicationGuildCommands(process.env.CLIENT, process.env.DEV_GUILD), {
|
2021-08-26 16:59:00 -03:00
|
|
|
body: commandsData,
|
2021-08-17 13:36:02 -03:00
|
|
|
},
|
2021-08-16 20:32:30 -03:00
|
|
|
);
|
2021-08-08 09:49:22 -03:00
|
|
|
|
|
|
|
|
}
|
2021-08-16 20:32:30 -03:00
|
|
|
catch (error) {
|
|
|
|
|
console.error(error);
|
|
|
|
|
}
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 21:05:23 -03:00
|
|
|
})();
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 21:05:23 -03:00
|
|
|
const eventFolders = fs.readdirSync('./events');
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 21:05:23 -03:00
|
|
|
for (const folder of eventFolders) {
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 21:05:23 -03:00
|
|
|
const eventFiles = fs.readdirSync(`./events/${folder}`).filter(file => file.endsWith('.js'));
|
2021-08-08 09:49:22 -03:00
|
|
|
|
2021-08-16 21:05:23 -03:00
|
|
|
for (const file of eventFiles) {
|
2021-08-16 20:32:30 -03:00
|
|
|
|
2021-08-16 21:05:23 -03:00
|
|
|
const event = require(`./events/${folder}/${file}`);
|
2021-08-16 20:32:30 -03:00
|
|
|
|
2021-08-17 13:36:02 -03:00
|
|
|
if (event.once) {
|
2021-08-16 21:05:23 -03:00
|
|
|
client.once(event.name, (...args) => event.execute(...args, client));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
client.on(event.name, (...args) => event.execute(...args, client));
|
|
|
|
|
}
|
2021-08-08 09:49:22 -03:00
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-16 21:05:23 -03:00
|
|
|
}
|
|
|
|
|
|
2021-08-27 13:28:12 -03:00
|
|
|
client.login(process.env.TOKEN);
|