Files
dashboard
src
.dockerignore
.eslintrc.json
.gitignore
docker-compose.yml
Dockerfile
package.json
README.md
SETUP_GUIDE.md
Code
55 3,590
src/index.js
import { Client, GatewayIntentBits, Partials, Collection } from 'discord.js';
import { config } from 'dotenv';
import mongoose from 'mongoose';
import { readdirSync } from 'fs';
import { fileURLToPath } from 'url';
import { dirname, join } from 'path';
import chalk from 'chalk';
import logger from './utils/logger.js';
config();
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildBans,
GatewayIntentBits.GuildEmojisAndStickers,
GatewayIntentBits.GuildIntegrations,
GatewayIntentBits.GuildWebhooks,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMessageTyping,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
GatewayIntentBits.DirectMessageTyping,
GatewayIntentBits.MessageContent,
],
partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction,
Partials.User,
Partials.GuildMember,
],
});
client.commands = new Collection();
client.cooldowns = new Collection();
client.musicQueues = new Collection();
client.verificationSessions = new Collection();
client.activeTickets = new Collection();
async function connectDatabase() {
try {
await mongoose.connect(process.env.MONGODB_URI);
logger.info(chalk.green('✓') + ' Connected to MongoDB');
} catch (error) {
logger.error('Failed to connect to MongoDB:', error);
process.exit(1);
}
}
async function loadHandlers() {
const handlersPath = join(__dirname, 'handlers');
const handlerFiles = readdirSync(handlersPath).filter(file => file.endsWith('.js'));
for (const file of handlerFiles) {
const { default: handler } = await import(`./handlers/${file}`);
await handler(client);
logger.info(`Loaded handler: ${chalk.cyan(file)}`);
}
}
async function startBot() {
try {
logger.info(chalk.bold.blue('Starting NexusBot...'));
await connectDatabase();
await loadHandlers();
await client.login(process.env.DISCORD_TOKEN);
} catch (error) {
logger.error('Failed to start bot:', error);
process.exit(1);
}
}
process.on('unhandledRejection', (error) => {
logger.error('Unhandled promise rejection:', error);
});
process.on('uncaughtException', (error) => {
logger.error('Uncaught exception:', error);
process.exit(1);
});
startBot();
export default client;