LBTRD-discord-bot/src/index.js

43 lines
1.1 KiB
JavaScript
Raw Normal View History

2026-06-04 15:58:20 +02:00
import "dotenv/config";
import { Client, GatewayIntentBits } from "discord.js";
const TARGET_USER_ID = "541298246971162636";
2026-06-04 16:07:00 +02:00
const LINK_PATTERN = /(?:https?:\/\/|www\.|discord\.gg\/|discord\.com\/invite\/|\[[^\]]+\]\([^\)]+\))/i;
2026-06-04 15:58:20 +02:00
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) => {
2026-06-04 16:07:00 +02:00
console.log(`Received message from ${message.author.tag}: ${message.content}`);
2026-06-04 15:58:20 +02:00
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);