Files
JogyoGaori/index.js
2025-08-16 02:43:23 +09:00

72 lines
2.3 KiB
JavaScript

require('dotenv').config();
console.log('index.js is being executed');
const { Client, GatewayIntentBits, Partials, Collection } = 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 client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
],
partials: [Partials.Channel],
});
// Load data and setup process handlers
loadData();
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'));
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));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
logger.info('Attempting to log in with token...');
client.login(process.env.DISCORD_TOKEN).catch(e => {
logger.error(`Failed to login: ${e.message}`);
process.exit(1);
});