require('dotenv').config(); const { Client, GatewayIntentBits } = require('discord.js'); const fs = require('fs'); const path = require('path'); const { clientId } = require('./config.json'); // Correct path for config.json const client = new Client({ intents: [GatewayIntentBits.Guilds] }); // Dynamically load all commands from the commands and moderation folders client.commands = new Map(); const folders = ['commands', 'moderation']; for (const folder of folders) { const folderPath = path.join(__dirname, 'src', folder); const files = fs.readdirSync(folderPath).filter(file => file.endsWith('.js')); for (const file of files) { const command = require(`./src/${folder}/${file}`); client.commands.set(command.data.name, command); } } // Import the deploy.js from the 'src' folder to handle command registration and deployment const { deployCommands } = require('./src/deploy'); // Start the bot client.once('ready', async () => { console.log(`Logged in as ${client.user.tag}!`); // Deploy commands globally, passing the client object await deployCommands(client); }); // Handle interactions (commands) client.on('interactionCreate', async (interaction) => { if (!interaction.isCommand()) return; const command = client.commands.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 }); } }); // Log the bot in using the token from the .env file client.login(process.env.DISCORD_TOKEN);