2025-11-20 21:59:42 +01:00
|
|
|
|
import 'dotenv/config';
|
2025-11-25 20:56:32 +01:00
|
|
|
|
import fs from 'fs';
|
|
|
|
|
|
import { Client, GatewayIntentBits, Options, Events, Collection } from 'discord.js';
|
2025-11-21 09:52:32 +01:00
|
|
|
|
import firstDetector from './detectors/allDetector.js';
|
2025-11-20 20:21:04 +01:00
|
|
|
|
|
2025-11-25 20:56:32 +01:00
|
|
|
|
|
|
|
|
|
|
// --- Configuration Client et Intents ---
|
2025-11-20 20:21:04 +01:00
|
|
|
|
const client = new Client({
|
|
|
|
|
|
makeCache: Options.cacheWithLimits({
|
2025-11-25 20:18:47 +01:00
|
|
|
|
MessageManager: 5, // opti de RAM mais 0 est trop agressif
|
|
|
|
|
|
ThreadManager: 0, // peut rester a 0 car peu utilisé
|
|
|
|
|
|
// UserManager: 0,
|
|
|
|
|
|
//ThreadManager: 0,
|
2025-11-25 20:56:32 +01:00
|
|
|
|
// commentées pour laisser par défaut, pas d'impact vu la RAM dispo
|
|
|
|
|
|
|
2025-11-20 20:21:04 +01:00
|
|
|
|
}),
|
|
|
|
|
|
intents: [
|
|
|
|
|
|
GatewayIntentBits.Guilds,
|
|
|
|
|
|
GatewayIntentBits.GuildMessages,
|
2025-11-25 20:56:32 +01:00
|
|
|
|
GatewayIntentBits.MessageContent, // required pour les détecteurs
|
2025-11-20 20:21:04 +01:00
|
|
|
|
]
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2025-11-25 20:56:32 +01:00
|
|
|
|
// --- Gestion des Événements ---
|
|
|
|
|
|
|
|
|
|
|
|
// 1. login réussi
|
|
|
|
|
|
client.on(Events.ClientReady, () => {
|
|
|
|
|
|
console.log(`[SUCCESS] Logged in as ${client.user?.tag}`);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 2. gestion des commandes slash
|
|
|
|
|
|
client.on(Events.InteractionCreate, async interaction => {
|
|
|
|
|
|
// check que ça soit bien commande slash
|
|
|
|
|
|
if (!interaction.isChatInputCommand()) return;
|
2025-11-25 20:18:47 +01:00
|
|
|
|
|
2025-11-25 20:56:32 +01:00
|
|
|
|
const command = client.commands.get(interaction.commandName);
|
|
|
|
|
|
if (!command) return;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
await command.execute(interaction);
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
|
console.error('Erreur exécution commande slash:', error);
|
|
|
|
|
|
// message d'erreur (si besoin), montré qu'à l'auteur
|
|
|
|
|
|
if (interaction.replied || interaction.deferred) {
|
|
|
|
|
|
await interaction.followUp({ content: 'Erreur lors de l’exécution de la commande !', ephemeral: true });
|
|
|
|
|
|
} else {
|
|
|
|
|
|
await interaction.reply({ content: 'Erreur lors de l’exécution de la commande !', ephemeral: true });
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// 3. Gestion des Messages (Détecteurs Passifs)
|
|
|
|
|
|
client.on('messageCreate', async (message) => {
|
2025-11-21 09:52:32 +01:00
|
|
|
|
if (message.author.bot) return;
|
2025-11-20 22:33:51 +01:00
|
|
|
|
|
2025-11-20 20:21:04 +01:00
|
|
|
|
try {
|
2025-11-25 20:18:47 +01:00
|
|
|
|
const reply = await firstDetector.createReply(message);
|
2025-11-21 09:52:32 +01:00
|
|
|
|
if (reply) await message.reply(reply);
|
2025-11-20 20:21:04 +01:00
|
|
|
|
} catch (e) {
|
2025-11-21 09:52:32 +01:00
|
|
|
|
console.error('Erreur détecteur:', e);
|
2025-11-20 20:21:04 +01:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
2025-11-25 20:56:32 +01:00
|
|
|
|
// --- connexion ---
|
|
|
|
|
|
client.login(process.env.DISCORD_TOKEN);
|