import { Client, GatewayIntentBits } from "discord.js"; import fetch from "node-fetch"; const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent ] }); const DISCORD_TOKEN = process.env.DISCORD_TOKEN; const N8N_WEBHOOK = process.env.N8N_WEBHOOK; client.on("messageCreate", async (message) => { if (message.author.bot) return; try { const response = await fetch(N8N_WEBHOOK, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ text: message.content, user: message.author.username }) }); const data = await response.json(); if (data.reply) { await message.reply(data.reply); } } catch (err) { console.error("Erreur:", err); message.reply("⚠️ Erreur avec le chatbot."); } }); client.login(DISCORD_TOKEN);