This repository has been archived on 2025-10-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Templated.djs/index.js

105 lines
2.3 KiB
JavaScript
Raw Normal View History

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');
const console = require('./functions/meta/console');
2021-08-08 09:49:22 -03:00
const client = new Client({
intents: [Intents.FLAGS.GUILDS],
});
2021-08-08 09:49:22 -03:00
client.commands = new Collection();
2021-08-08 09:49:22 -03:00
const commandFolders = fs.readdirSync('./commands');
const commands = [];
const commandsData = {
guild: [],
perGuild: [],
global: [],
};
2021-08-08 09:49:22 -03:00
for (const folder of commandFolders) {
2021-08-08 09:49:22 -03:00
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
2021-08-08 09:49:22 -03:00
for (const file of commandFiles) {
2021-08-08 09:49:22 -03:00
const command = require(`./commands/${folder}/${file}`);
if(command.properties) command.properties.folder = folder;
else command.properties = { folder: folder };
if(!command.properties.guild) command.properties.guild = process.env.DEV_GUILD;
commands.push(command);
2021-08-08 09:49:22 -03:00
if(command.properties.type.includes('guild')) {
commandsData.guild.push(command.data.toJSON());
}
if(command.properties.type.includes('per-guild')) {
commandsData.perGuild.push(command.data.toJSON());
}
if(command.properties.type.includes('per-guild')) {
commandsData.global.push(command.data.toJSON());
}
2021-08-08 09:49:22 -03:00
}
}
2021-08-08 09:49:22 -03:00
const rest = new REST({
version: '9',
}).setToken(process.env.TOKEN);
2021-08-08 09:49:22 -03:00
module.exports = { commands, commandsData, rest };
(async () => {
2021-08-08 09:49:22 -03:00
try {
2021-08-08 09:49:22 -03:00
await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT, process.env.DEV_GUILD), {
body: commandsData.guild,
},
);
2021-08-08 09:49:22 -03:00
}
catch (error) {
console.error(error);
}
2021-08-08 09:49:22 -03:00
})();
2021-08-08 09:49:22 -03:00
const eventFolders = fs.readdirSync('./events');
2021-08-08 09:49:22 -03:00
for (const folder of eventFolders) {
2021-08-08 09:49:22 -03:00
const eventFiles = fs.readdirSync(`./events/${folder}`).filter(file => file.endsWith('.js'));
2021-08-08 09:49:22 -03:00
for (const file of eventFiles) {
const event = require(`./events/${folder}/${file}`);
if (event.once) {
client.once(event.name, (...args) => {
console.system(`New event fired: ${event.name}`);
event.execute(...args, client);
console.system(`Event finished: ${event.name}`);
});
}
else {
client.on(event.name, (...args) => {
console.system(`New event fired: ${event.name}`);
event.execute(...args, client);
console.system(`Event finished: ${event.name}`);
});
}
2021-08-08 09:49:22 -03:00
}
}
client.login(process.env.TOKEN);