const { Client, GatewayIntentBits, Collection } = require('discord.js'); const fs = require('fs'); const path = require('path'); const { token, prefix } = require('./config.json'); const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] }); client.commands = new Collection(); client.slashcommands = new Collection(); // Load prefix commands const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); for (const file of commandFiles) { const command = require(`./commands/${file}`); client.commands.set(command.name, command); } // Load slash commands const slashCommandFiles = fs.readdirSync('./slashcommands').filter(file => file.endsWith('.js')); for (const file of slashCommandFiles) { const command = require(`./slashcommands/${file}`); client.slashcommands.set(command.data.name, command); } client.once('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); client.on('messageCreate', message => { if (!message.content.startsWith(prefix) || message.author.bot) return; const args = message.content.slice(prefix.length).trim().split(/ +/); const commandName = args.shift().toLowerCase(); if (!client.commands.has(commandName)) return; const command = client.commands.get(commandName); try { command.execute(message, args); } catch (error) { console.error(error); message.reply('There was an error executing that command!'); } }); client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) return; const command = client.slashcommands.get(interaction.commandName); if (!command) return; try { await command.execute(interaction); } catch (error) { console.error(error); await interaction.reply({ content: 'There was an error executing that command!', ephemeral: true }); } }); client.login(token);