Files
commands
data
events
handlers
utils
config.json
index.js
package.json
README.md
Code
18 822
index.js
require('dotenv').config();
const { Client, GatewayIntentBits, Partials } = require('discord.js');
const config = require('./config.json');
const { loadCommands } = require('./handlers/commandHandler');
const { loadEvents } = require('./handlers/eventHandler');
const SettingsStore = require('./utils/settingsStore');
const AntiSpamHandler = require('./handlers/antiSpamHandler');
const logger = require('./utils/logger');
const token = process.env.DISCORD_TOKEN;
if (!token || token === 'replace_with_your_bot_token') {
logger.error('DISCORD_TOKEN is missing. Copy .env.example to .env and add your bot token.');
} else {
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
],
partials: [Partials.Channel]
});
// Shared services are attached to the client so every event uses one store and detector.
client.commands = loadCommands();
client.settingsStore = new SettingsStore();
client.antiSpam = new AntiSpamHandler(client);
loadEvents(client);
process.on('unhandledRejection', (error) => logger.error('Unhandled promise rejection:', error));
process.on('uncaughtException', (error) => logger.error('Uncaught exception:', error));
client.login(token).catch((error) => logger.error('Unable to log in to Discord:', error));
}