const fs = require('fs'); const path = require('path'); const { REST } = require('@discordjs/rest'); const { Routes } = require('discord-api-types/v9'); const { clientId, guildId, token } = require('./config.json'); // Funkció az összes fájl lekéréséhez a megadott könyvtárban function getFiles(dir) { const files = fs.readdirSync(dir, { withFileTypes: true }); let commandFiles = []; for (const file of files) { if (file.isDirectory()) { commandFiles = [ ...commandFiles, ...getFiles(path.join(dir, file.name)), ]; } else if (file.name.endsWith('.js')) { commandFiles.push(path.join(dir, file.name)); } } return commandFiles; } // Parancsok gyűjtése let commands = []; const commandFiles = getFiles('./commands'); for (const file of commandFiles) { const command = require(file); if (command.data) { commands.push(command.data.toJSON()); } else { console.error(`Failed to load command ${file}: No 'data' property found.`); } } // REST client létrehozása const rest = new REST({ version: '9' }).setToken(token); (async () => { try { console.log('Started refreshing application (/) commands.'); // Parancsok regisztrálása await rest.put( Routes.applicationGuildCommands(clientId, guildId), { body: commands }, ); console.log('Successfully registered application commands!'); } catch (error) { console.error('Failed to register application commands:', error); } })();