require('dotenv').config(); const { Client, GatewayIntentBits, Collection } = require('discord.js'); const fs = require('fs'); const path = require('path'); const client = new Client({ intents: [GatewayIntentBits.Guilds] }); client.commands = new Collection(); client.moderation = new Collection(); // Dynamically load commands and moderation files const commandFolders = ['commands', 'moderation']; for (const folder of commandFolders) { const commandPath = path.join(__dirname, 'src', folder); const commandFiles = fs.readdirSync(commandPath).filter(file => file.endsWith('.js')); for (const file of commandFiles) { const command = require(`./src/${folder}/${file}`); client[folder === 'commands' ? 'commands' : 'moderation'].set(command.data.name, command); } } client.once('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) return; const command = client.commands.get(interaction.commandName) || client.moderation.get(interaction.commandName); if (!command) return; try { await command.execute(interaction); } catch (error) { console.error(error); await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); } }); client.login(process.env.DISCORD_TOKEN);