Created the command type `per-guild` these commands are registered when the bot enters a new guild, different of the global type, they can have permissions edited (the permissions system need to be developed yet). `guild` commands will be registered just in the development guild (probably the purpose of them need to be rethought). The reload command became adapted to be compatible with the command type system. When a command is reloaded, it's on all other guilds.
105 lines
2.3 KiB
JavaScript
105 lines
2.3 KiB
JavaScript
const { Client, Collection, Intents } = require('discord.js');
|
|
const { REST } = require('@discordjs/rest');
|
|
const { Routes } = require('discord-api-types/v9');
|
|
|
|
const fs = require('fs');
|
|
|
|
const console = require('./functions/meta/console');
|
|
|
|
const client = new Client({
|
|
intents: [Intents.FLAGS.GUILDS],
|
|
});
|
|
|
|
client.commands = new Collection();
|
|
|
|
const commandFolders = fs.readdirSync('./commands');
|
|
const commands = [];
|
|
const commandsData = {
|
|
guild: [],
|
|
perGuild: [],
|
|
global: [],
|
|
};
|
|
|
|
for (const folder of commandFolders) {
|
|
|
|
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter(file => file.endsWith('.js'));
|
|
|
|
for (const file of commandFiles) {
|
|
|
|
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);
|
|
|
|
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());
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
const rest = new REST({
|
|
version: '9',
|
|
}).setToken(process.env.TOKEN);
|
|
|
|
module.exports = { commands, commandsData, rest };
|
|
|
|
(async () => {
|
|
|
|
try {
|
|
|
|
await rest.put(
|
|
Routes.applicationGuildCommands(process.env.CLIENT, process.env.DEV_GUILD), {
|
|
body: commandsData.guild,
|
|
},
|
|
);
|
|
|
|
}
|
|
catch (error) {
|
|
console.error(error);
|
|
}
|
|
|
|
})();
|
|
|
|
const eventFolders = fs.readdirSync('./events');
|
|
|
|
for (const folder of eventFolders) {
|
|
|
|
const eventFiles = fs.readdirSync(`./events/${folder}`).filter(file => file.endsWith('.js'));
|
|
|
|
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}`);
|
|
});
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
client.login(process.env.TOKEN); |