Files
src
.gitignore
config.json
deploy-commands.js
index.js
package.json
README.md
Code
110 4,863
index.js
require('dotenv').config();
const { Client, GatewayIntentBits, Partials, Collection } = require('discord.js');
const { connectDatabase } = require('./src/utils/database');
const { loadCommands } = require('./src/handlers/commandHandler');
const { loadEvents } = require('./src/handlers/eventHandler');
const { loadButtons } = require('./src/handlers/buttonHandler');
const logger = require('./src/utils/logger');
const cron = require('node-cron');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
],
partials: [
Partials.Channel,
Partials.Message,
Partials.Reaction,
Partials.GuildMember,
Partials.User
],
allowedMentions: { parse: ['users', 'roles'], repliedUser: true }
});
client.commands = new Collection();
client.buttons = new Collection();
client.cooldowns = new Collection();
client.config = require('./config.json');
async function init() {
try {
await connectDatabase();
await loadCommands(client);
await loadEvents(client);
await loadButtons(client);
await client.login(process.env.DISCORD_TOKEN);
scheduleJobs(client);
} catch (error) {
logger.error('Failed to initialize bot:', error);
process.exit(1);
}
}
function scheduleJobs(client) {
cron.schedule('* * * * *', async () => {
const { checkReminders } = require('./src/utils/reminderScheduler');
await checkReminders(client);
});
cron.schedule('* * * * *', async () => {
const { checkGiveaways } = require('./src/utils/giveawayScheduler');
await checkGiveaways(client);
});
}
process.on('unhandledRejection', (reason, promise) => {
logger.error('Unhandled Rejection at:', promise, 'reason:', reason);
});
process.on('uncaughtException', (error) => {
logger.error('Uncaught Exception:', error);
});
init();
module.exports = client;