Files
api
commands
config
events
handlers
models
utils
DEPLOYMENT_GUIDE.md
index.js
package.json
README.md
SETUP_GUIDE.md
sharding.js
Code
58 4,642
index.js
const { Client, GatewayIntentBits, Partials, Collection } = require('discord.js');
const mongoose = require('mongoose');
const dotenv = require('dotenv');
const logger = require('./utils/logger');
const commandHandler = require('./handlers/commandHandler');
const eventHandler = require('./handlers/eventHandler');
const errorHandler = require('./handlers/errorHandler');
dotenv.config();
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.DirectMessages,
GatewayIntentBits.MessageContent
],
partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction,
Partials.User,
Partials.GuildMember
],
allowedMentions: { parse: ['users', 'roles'], repliedUser: true }
});
client.commands = new Collection();
client.cooldowns = new Collection();
client.config = require('./config/config');
client.logger = logger;
mongoose.connect(process.env.MONGODB_URI, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
logger.info('โ
Connected to MongoDB');
}).catch(err => {
logger.error('โ MongoDB connection error:', err);
process.exit(1);
});
commandHandler(client);
eventHandler(client);
errorHandler(client);
process.on('unhandledRejection', (error) => {
logger.error('Unhandled promise rejection:', error);
});
process.on('uncaughtException', (error) => {
logger.error('Uncaught exception:', error);
});
client.login(process.env.DISCORD_TOKEN).catch(err => {
logger.error('Failed to login:', err);
process.exit(1);
});
module.exports = client;