const { token, guildId } = require('./config.json'); const { Client, Events, GatewayIntentBits, Collection } = require('discord.js'); const fs = require('fs'); const path = require('path'); // Létrehozzuk a botot const client = new Client({ intents: [ GatewayIntentBits.Guilds,, ] }); // Parancsok betöltése client.commands = getCommands(path.join(__dirname, 'commands')); // Bot elindulásakor client.once(Events.ClientReady, () => { console.log('Bot is online!'); }); // Interakciók kezelése client.on(Events.InteractionCreate, async interaction => { if (!interaction.isCommand()) return; const command = client.commands.get(interaction.commandName); if (!command) { console.error(`Command ${interaction.commandName} not found.`); return; } try { await command.execute(interaction); } catch (error) { console.error('Error executing command:', error); await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true }); } }); // Bot bejelentkezés client.login(token); // Parancsok betöltése function getCommands(dir) { const commands = new Collection(); const commandFiles = getFiles(dir); for (const commandFile of commandFiles) { try { const command = require(commandFile); if (command.data && typeof command.data === 'object') { commands.set(command.data.name, command); } else { console.error(`Failed to load command ${commandFile}: No 'data' property found.`); } } catch (error) { console.error(`Failed to load command ${commandFile}:`, error); } } return commands; } // Fájlok beolvasása 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; }