Files
commands
dashboard
events
utils
config.json
database.js
index.js
package.json
README.md
Code
25 3,053
index.js
const { Client, GatewayIntentBits, Collection } = require('discord.js');
const fs = require('fs');
const path = require('path');
require('dotenv').config();
const Dashboard = require('./dashboard/server');
const database = require('./database');
const config = require('./config.json');
const AutoRewardManager = require('./utils/autoRewardManager');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.MessageContent
]
});
client.commands = new Collection();
client.invites = new Map();
client.voiceTime = new Map();
client.autoRewardManager = null;
const loadCommands = (dir) => {
const files = fs.readdirSync(dir);
for (const file of files) {
const filePath = path.join(dir, file);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
loadCommands(filePath);
} else if (file.endsWith('.js')) {
const command = require(filePath);
if (command.name) {
client.commands.set(command.name, command);
console.log(`โ
Loaded command: ${command.name}`);
}
}
}
};
const commandsPath = path.join(__dirname, 'commands');
if (fs.existsSync(commandsPath)) {
loadCommands(commandsPath);
}
const eventsPath = path.join(__dirname, 'events');
if (fs.existsSync(eventsPath)) {
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(path.join(eventsPath, file));
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
console.log(`โ
Loaded event: ${event.name}`);
}
}
client.on('error', console.error);
client.on('warn', console.warn);
process.on('unhandledRejection', error => {
console.error('โ Unhandled promise rejection:', error);
});
client.once('ready', () => {
client.autoRewardManager = new AutoRewardManager(client);
client.autoRewardManager.start();
const dashboard = new Dashboard(client, database, config);
dashboard.start();
});
client.login(process.env.DISCORD_TOKEN).catch(error => {
console.error('โ Failed to login! Check your DISCORD_TOKEN in .env file');
console.error(error.message);
process.exit(1);
});