Files
commands
database
events
handlers
utils
bot.js
config.json
package.json
Code
19 1,788
bot.js
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const { initializeDatabase } = require('./database/connection');
const eventHandler = require('./handlers/eventHandler');
const commandHandler = require('./handlers/commandHandler');
require('dotenv').config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
client.commands = new Collection();
client.prefixCommands = new Collection();
async function startBot() {
try {
console.log('[BOT] Initializing database...');
initializeDatabase();
console.log('[BOT] Loading commands and events...');
await commandHandler(client);
await eventHandler(client);
console.log('[BOT] Logging in...');
await client.login(process.env.DISCORD_TOKEN);
} catch (error) {
console.error('[BOT] Failed to start:', error);
process.exit(1);
}
}
process.on('unhandledRejection', error => {
console.error('[ERROR] Unhandled promise rejection:', error);
});
process.on('SIGINT', () => {
console.log('[BOT] Shutting down gracefully...');
client.destroy();
process.exit(0);
});
startBot();