require('dotenv').config(); const { Client, GatewayIntentBits, Partials, Collection, SeparatorComponent } = require('discord.js'); const fs = require('fs'); const path = require('path'); const client = new Client({ intents: [ GatewayIntentBits. GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent ], partials: [Partials.Channel] }); // Chargement des commandes client.commands = new Collection(); const commandFiles = fs.readdirSync(path.join(__dirname, 'commands')).filter(file => file.endsWith('.js')); for (const file of commandFiles) { const command = require(path.join(__dirname, 'commands', file)); if (!command.data || !command.data.name) { console.warn(`[AVERTISSEMENT] La commande ${file} est invalide ou mal configurée.`); continue; } client.commands.set(command.data.name, command); } client.once('ready', () => { console.log(`✅ Connecté en tant que ${client.user.tag}`); }); // Gestion des commandes slash client.on('interactionCreate', async (interaction) => { if (!interaction.isChatInputCommand()) return; const command = client.commands.get(interaction.commandName); if (!command) return; try { if (command.executeSlash) { await command.executeSlash(interaction); } } catch (error) { console.error(error); if (!interaction.replied && !interaction.deferred) { try { await interaction.reply({ content: '❌ Une erreur est survenue.', ephemeral: true }); } catch (replyError) { console.error('Erreur lors de l\'envoi du message d\'erreur:', replyError); } } } }); // Préfixe pour commandes texte const prefix = '-'; client.on('messageCreate', async (message) => { if (!message.content.startsWith(prefix) || message.author.bot) return; const args = message.content.slice(prefix.length).trim().split(/ +/); const commandName = args.shift().toLowerCase(); const command = client.commands.find(cmd => cmd.name === commandName || (cmd.aliases && cmd.aliases.includes(commandName)) ); if (!command) return; try { if (command.executePrefix) { await command.executePrefix(message, client, args); } } catch (error) { console.error(error); await message.reply('❌ Une erreur est survenue.'); } }); client.login(process.env.TOKEN);