LBTRD-discord-bot/src/index.js
2026-06-04 16:07:00 +02:00

42 lines
1.1 KiB
JavaScript

import "dotenv/config";
import { Client, GatewayIntentBits } from "discord.js";
const TARGET_USER_ID = "541298246971162636";
const LINK_PATTERN = /(?:https?:\/\/|www\.|discord\.gg\/|discord\.com\/invite\/|\[[^\]]+\]\([^\)]+\))/i;
const WARNING_MESSAGE =
"Alerte: Ce lien a été envoyé par Nesta. Ne cliquez SURTOUT PAS s'il y a des gens autour de vous.";
if (!process.env.DISCORD_TOKEN) {
throw new Error("Missing DISCORD_TOKEN in environment variables.");
}
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
});
client.on("messageCreate", async (message) => {
console.log(`Received message from ${message.author.tag}: ${message.content}`);
if (message.author.bot) {
return;
}
if (!message.guild) {
return;
}
if (message.author.id !== TARGET_USER_ID) {
return;
}
if (!LINK_PATTERN.test(message.content)) {
return;
}
await message.channel.send(WARNING_MESSAGE);
});
client.once("clientReady", () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.login(process.env.DISCORD_TOKEN);