forked from jonasmerlin/rollenspiel-nordwest-bot
Init
This commit is contained in:
+15
@@ -0,0 +1,15 @@
|
||||
import { Client, Events, GatewayIntentBits, TextChannel } from 'discord.js';
|
||||
|
||||
import { config } from './config';
|
||||
|
||||
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
|
||||
|
||||
client.on(Events.ThreadCreate, async (thread) => {
|
||||
if (thread.parentId !== config.forumChannelId) return;
|
||||
const channel = await client.channels.fetch(config.announceChannelId);
|
||||
if (channel instanceof TextChannel) {
|
||||
await channel.send(`Neues Event: **${thread.name}** — ${thread.url}`);
|
||||
}
|
||||
});
|
||||
|
||||
client.login(config.botToken);
|
||||
@@ -0,0 +1,21 @@
|
||||
import 'dotenv/config';
|
||||
|
||||
function readRequiredEnv(name: string): string {
|
||||
const value = process.env[name]?.trim();
|
||||
|
||||
// Centralizing this check keeps the rest of the bot free from defensive
|
||||
// env handling and makes startup fail immediately with a clear message.
|
||||
if (!value) {
|
||||
throw new Error(
|
||||
`Missing required environment variable ${name}. Set it in the environment or in a .env file.`,
|
||||
);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
export const config = {
|
||||
botToken: readRequiredEnv('DISCORD_BOT_TOKEN'),
|
||||
forumChannelId: readRequiredEnv('DISCORD_FORUM_CHANNEL_ID'),
|
||||
announceChannelId: readRequiredEnv('DISCORD_ANNOUNCE_CHANNEL_ID'),
|
||||
};
|
||||
Reference in New Issue
Block a user