Files
commands
events
utils
config.json
deploy-commands.js
index.js
package.json
Code
102 5,155
index.js
const { Client, GatewayIntentBits, Collection, Partials } = require('discord.js');
const fs = require('fs');
const path = require('path');
require('dotenv').config();
const db = require('./utils/database');
const { startVoiceTracking } = require('./utils/voiceTracker');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildMessageReactions,
],
partials: [
Partials.Message,
Partials.Channel,
Partials.GuildMember,
Partials.User,
Partials.Reaction,
Partials.GuildScheduledEvent,
],
});
client.commands = new Collection();
// ─── Load commands (recursive) ────────────────────────────────────────────────
function loadCommands(dir) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
loadCommands(fullPath);
} else if (entry.name.endsWith('.js')) {
const command = require(fullPath);
if (command.data && command.execute) {
client.commands.set(command.data.name, command);
console.log(`[CMD] Loaded: ${command.data.name}`);
}
}
}
}
loadCommands(path.join(__dirname, 'commands'));
// ─── Load events (recursive) ──────────────────────────────────────────────────
function loadEvents(dir) {
const entries = fs.readdirSync(dir, { withFileTypes: true });
for (const entry of entries) {
const fullPath = path.join(dir, entry.name);
if (entry.isDirectory()) {
loadEvents(fullPath);
} else if (entry.name.endsWith('.js')) {
const event = require(fullPath);
if (!event.name) return;
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
console.log(`[EVT] Loaded: ${event.name} (${path.relative(__dirname, fullPath)})`);
}
}
}
loadEvents(path.join(__dirname, 'events'));
client.on('error', err => console.error('[CLIENT ERROR]', err));
process.on('unhandledRejection', err => console.error('[UNHANDLED REJECTION]', err));
db.init();
startVoiceTracking(client);
client.login(process.env.DISCORD_TOKEN);