Files
commands
events
utils
.gitignore
config.json
index.js
package.json
Code
16 512
index.js
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const fs = require('fs');
const path = require('path');
require('dotenv').config();
const config = require('./config.json');
const logger = require('./utils/logger');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent
]
});
client.commands = new Collection();
client.config = config;
const loadCommands = () => {
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
logger.info(`Loaded command: ${command.name}`);
}
};
const loadEvents = () => {
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
logger.info(`Loaded event: ${event.name}`);
}
};
loadCommands();
loadEvents();
client.on('error', error => {
logger.error('Client error:', error);
});
process.on('unhandledRejection', error => {
logger.error('Unhandled promise rejection:', error);
});
client.login(process.env.DISCORD_TOKEN);