//Boring boring initialization stuff const fs = require('node:fs'); const path = require('node:path'); const { Client, Collection, Events, GatewayIntentBits } = require('discord.js'); const { token } = require('./config.json'); const client = new Client({ intents: [GatewayIntentBits.Guilds] }); //Handle commands client.commands = new Collection(); //Command Loading const foldersPath = path.join(__dirname, 'commands'); const commandFolders = fs.readdirSync(foldersPath); for(const folder of commandFolders) { const commandPath = path.join(foldersPath, folder); const commandFiles = fs.readdirSync(commandPath).filter(file => file.endsWith('.js')); for (const file of commandFiles) { const filePath = path.join(commandPath, file); const command = require(filePath); if ('data' in command && 'execute' in command) { client.commands.set(command.data.name, command); } else { console.log(`WARN: Command at ${filePath} is missing 'data' and/or 'execute' properties.`); } } } //Command Interaction Processing client.on(Events.InteractionCreate, async interaction => { if (!interaction.isChatInputCommand()) return; const command = interaction.client.commands.get(interaction.commandName); if (!command) { console.error(`ERR: Command "${interaction.commandName}" not found`); return; } try { await command.execute(interaction); } catch (error) { console.error(error); if (interaction.replied || interaction.deferred) { await interaction.followUp({ content: `ERROR!`, ephermal: true}); } else { await interaction.reply({ content: `ERROR!`, ephermal: true}); } } }); //Log the bot in with the token supplied in config.json client.once(Events.ClientReady, readyClient => { console.log(`Ready! Logged in as ${readyClient.user.tag}`); }); client.login(token);