Caching improvements
This commit is contained in:
41
index.js
41
index.js
@@ -1,10 +1,11 @@
|
||||
require('dotenv').config();
|
||||
const { Client, GatewayIntentBits, Partials, Collection } = require('discord.js');
|
||||
const { Client, GatewayIntentBits, Partials } = require('discord.js');
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const logger = require('./modules/colorfulLogger');
|
||||
const { loadData } = require('./src/data/dataManager');
|
||||
const { setupProcessHandlers } = require('./src/handlers/processHandlers');
|
||||
const { loadCommands } = require('./src/handlers/commandHandler');
|
||||
|
||||
const client = new Client({
|
||||
intents: [
|
||||
@@ -16,39 +17,13 @@ const client = new Client({
|
||||
partials: [Partials.Channel],
|
||||
});
|
||||
|
||||
// Load data and setup process handlers
|
||||
// Load data and commands
|
||||
loadData();
|
||||
loadCommands();
|
||||
|
||||
// Setup process handlers
|
||||
setupProcessHandlers(client);
|
||||
|
||||
// Load commands
|
||||
client.commands = new Collection();
|
||||
client.legacyCommands = new Collection();
|
||||
|
||||
const commandFolders = fs.readdirSync(path.join(__dirname, 'src', 'commands'));
|
||||
|
||||
for (const folder of commandFolders) {
|
||||
const commandFiles = fs.readdirSync(path.join(__dirname, 'src', 'commands', folder)).filter(file => file.endsWith('.js'));
|
||||
for (const file of commandFiles) {
|
||||
const filePath = path.join(__dirname, 'src', 'commands', folder, file);
|
||||
const command = require(filePath);
|
||||
|
||||
// Load slash command part
|
||||
if (command.data && command.execute) {
|
||||
client.commands.set(command.data.name, command);
|
||||
}
|
||||
|
||||
// Load legacy command part
|
||||
if (command.legacy) {
|
||||
client.legacyCommands.set(command.legacy.name, command.legacy);
|
||||
if (command.legacy.aliases) {
|
||||
command.legacy.aliases.forEach(alias => {
|
||||
client.legacyCommands.set(alias, command.legacy);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Load event handlers
|
||||
const eventsPath = path.join(__dirname, 'src', 'events');
|
||||
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
|
||||
@@ -57,9 +32,9 @@ for (const file of eventFiles) {
|
||||
const filePath = path.join(eventsPath, file);
|
||||
const event = require(filePath);
|
||||
if (event.once) {
|
||||
client.once(event.name, (...args) => event.execute(...args));
|
||||
client.once(event.name, (...args) => event.execute(...args, client));
|
||||
} else {
|
||||
client.on(event.name, (...args) => event.execute(...args));
|
||||
client.on(event.name, (...args) => event.execute(...args, client));
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user