Files
src
.gitignore
config.json
index.js
package.json
README.md
Code
25 1,554
index.js
const { Client, GatewayIntentBits, Collection, REST, Routes } = require('discord.js');
const { readdirSync } = require('fs');
const { join } = require('path');
require('dotenv').config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
]
});
client.commands = new Collection();
client.buttons = new Collection();
const Database = require('./src/database/Database');
const Logger = require('./src/utils/Logger');
const LanguageManager = require('./src/utils/LanguageManager');
const TicketManager = require('./src/utils/TicketManager');
client.db = new Database();
client.logger = new Logger();
client.lang = new LanguageManager();
client.tickets = new TicketManager(client);
const loadCommands = () => {
const commandFiles = readdirSync(join(__dirname, 'src', 'commands')).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(join(__dirname, 'src', 'commands', file));
client.commands.set(command.data.name, command);
client.logger.info(`Loaded command: ${command.data.name}`);
}
};
const loadEvents = () => {
const eventFiles = readdirSync(join(__dirname, 'src', 'events')).filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(join(__dirname, 'src', 'events', file));
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
client.logger.info(`Loaded event: ${event.name}`);
}
};
const loadButtons = () => {
const buttonFiles = readdirSync(join(__dirname, 'src', 'buttons')).filter(file => file.endsWith('.js'));
for (const file of buttonFiles) {
const button = require(join(__dirname, 'src', 'buttons', file));
client.buttons.set(button.customId, button);
client.logger.info(`Loaded button: ${button.customId}`);
}
};
const deployCommands = async () => {
const commands = [];
client.commands.forEach(command => {
commands.push(command.data.toJSON());
});
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);
try {
client.logger.info('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands }
);
client.logger.success('Successfully reloaded application (/) commands.');
} catch (error) {
client.logger.error('Error deploying commands:', error);
}
};
loadCommands();
loadEvents();
loadButtons();
client.login(process.env.DISCORD_TOKEN).then(() => {
deployCommands();
});
process.on('unhandledRejection', error => {
client.logger.error('Unhandled promise rejection:', error);
});