const { Client, GatewayIntentBits, Collection, Partials } = require('discord.js'); const fs = require('fs'); const path = require('path'); const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildVoiceStates, ], partials: [Partials.Message, Partials.Channel, Partials.GuildMember, Partials.Reaction], }); client.commands = new Collection(); const prefix = '-'; // تحميل الأوامر من مجلد commands const commandsPath = path.join(__dirname, 'commands'); const commandFiles = fs.existsSync(commandsPath) ? fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')) : []; for (const file of commandFiles) { const filePath = path.join(commandsPath, file); const command = require(filePath); if (Array.isArray(command)) { for (const cmd of command) { if (cmd.name && cmd.execute) { client.commands.set(cmd.name, cmd); } else { console.warn(`Command in ${file} is missing required properties.`); } } } else { if (command.name && command.execute) { client.commands.set(command.name, command); } else { console.warn(`Command in ${file} is missing required properties.`); } } } // تحميل ملفات الأحداث من مجلد events const eventsPath = path.join(__dirname, 'events'); if (fs.existsSync(eventsPath)) { const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js')); for (const file of eventFiles) { const filePath = path.join(eventsPath, file); const event = require(filePath); if (event.once) { client.once(event.name, (...args) => event.execute(client, ...args)); } else { client.on(event.name, (...args) => event.execute(client, ...args)); } } } // ربط ملف mute_un وتمرير client require('./commands/mute_un')(client); // تنفيذ أوامر البرفكس client.on('messageCreate', async (message) => { if (message.author.bot || !message.guild) return; if (!message.content.startsWith(prefix)) return; const args = message.content.slice(prefix.length).trim().split(/ +/); const cmdName = args.shift().toLowerCase(); const command = client.commands.get(cmdName) || client.commands.find(c => c.aliases && c.aliases.includes(cmdName)); if (!command) return; try { await command.execute(message, args, client); } catch (error) { console.error('Error executing command:', error); message.reply('**حدث خطأ أثناء تنفيذ الأمر.**'); } }); // حدث جاهزية البوت client.once('ready', () => { console.log(`✅ Bot is running as ${client.user.tag}`); }); // التعامل مع التفاعلات (select menus, modals) client.on('interactionCreate', async (interaction) => { try { if (interaction.isStringSelectMenu()) { // مثال: تمرير التفاعل لأمر mute إذا كان يدعم ذلك const command = client.commands.get('mute'); if (command && typeof command.handleSelectMenu === 'function') { return command.handleSelectMenu(interaction); } } else if (interaction.isModalSubmit()) { const command = client.commands.get('mute'); if (command && typeof command.handleModalSubmit === 'function') { return command.handleModalSubmit(interaction); } } } catch (error) { console.error('Error handling interaction:', error); } }); client.login('..');