This commit is contained in:
2025-09-06 14:15:41 +02:00
commit 6aa356f532
4 changed files with 72 additions and 0 deletions

15
Dockerfile Normal file
View File

@ -0,0 +1,15 @@
# Utilise Node.js LTS
FROM node:20-slim
# Crée un dossier de travail
WORKDIR /usr/src/app
# Copie package.json et installe les deps
COPY package*.json ./
RUN npm install --only=production
# Copie le reste du code
COPY . .
# Lance le bot
CMD ["node", "bot.js"]

36
bot.js Normal file
View File

@ -0,0 +1,36 @@
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);

10
docker-compose.yml Normal file
View File

@ -0,0 +1,10 @@
version: "3.9"
services:
discord-bot:
build: .
container_name: discord-bot
restart: unless-stopped
environment:
DISCORD_TOKEN: "${DISCORD_TOKEN}"
N8N_WEBHOOK: "${N8N_WEBHOOK}"

11
package.json Normal file
View File

@ -0,0 +1,11 @@
{
"name": "discord-n8n-bot",
"version": "1.0.0",
"main": "bot.js",
"type": "module",
"dependencies": {
"discord.js": "^14.14.1",
"node-fetch": "^3.3.2"
}
}