const fs = require('fs'); const { Client, GatewayIntentBits, Collection, REST, Routes } = require('discord.js'); const config = require('./config.json'); const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] }); client.commands = new Collection(); client.slashcommands = new Collection(); const slashcommandsArray = []; // Prefix commands mappa betöltése 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); } // Slashcommands mappa betöltése const slashCommandFiles = fs.readdirSync('./slashcommands').filter(file => file.endsWith('.js')); for (const file of slashCommandFiles) { const slashCommand = require(`./slashcommands/${file}`); client.slashcommands.set(slashCommand.data.name, slashCommand); slashcommandsArray.push(slashCommand.data.toJSON()); } client.once('ready', async () => { console.log(`Logged in as ${client.user.tag}!`); const rest = new REST({ version: '10' }).setToken(config.token); try { console.log('Started refreshing application (/) commands.'); // Töröljük a meglévő parancsokat, hogy elkerüljük a duplikációkat const existingCommands = await rest.get( Routes.applicationCommands(config.clientId) ); if (existingCommands.length) { await Promise.all( existingCommands.map(cmd => rest.delete(Routes.applicationCommand(config.clientId, cmd.id)) ) ); console.log('Cleared old commands.'); } // Regisztráljuk az új slash parancsokat await rest.put( Routes.applicationCommands(config.clientId), { body: slashcommandsArray } ); console.log('Successfully reloaded application (/) commands.'); } catch (error) { console.error('Error reloading commands:', error); } }); // Prefix parancsok kezelése client.on('messageCreate', message => { if (!message.content.startsWith(config.prefix) || message.author.bot) return; const args = message.content.slice(config.prefix.length).trim().split(/ +/); const commandName = args.shift().toLowerCase(); const command = client.commands.get(commandName); if (!command) return; try { command.execute(message, args); } catch (error) { console.error(error); message.reply('There was an error executing that command.'); } }); // Slash parancsok kezelése client.on('interactionCreate', async interaction => { if (!interaction.isCommand()) return; const slashCommand = client.slashcommands.get(interaction.commandName); if (!slashCommand) return; try { await slashCommand.execute(interaction); } catch (error) { console.error(error); await interaction.reply({ content: 'There was an error executing that command.', ephemeral: true }); } }); client.login(config.token);