From d6b1e0eba6da9220cc8732165d45d5f36ecefe59 Mon Sep 17 00:00:00 2001 From: TheoryOfNekomata Date: Thu, 30 May 2024 12:31:52 +0800 Subject: [PATCH] Add config Config is for setting up bot on first start. --- packages/discord-bot/.env.example | 5 +++++ packages/discord-bot/src/config.ts | 1 + packages/discord-bot/src/index.ts | 9 +++++---- 3 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 packages/discord-bot/.env.example diff --git a/packages/discord-bot/.env.example b/packages/discord-bot/.env.example new file mode 100644 index 0000000..2c04929 --- /dev/null +++ b/packages/discord-bot/.env.example @@ -0,0 +1,5 @@ +# Discord bot token. The bot must be added to the server first. +DISCORD_BOT_TOKEN= + +# Channel ID of the forum to proxy comments. +DISCORD_FORUM_CHANNEL_ID= diff --git a/packages/discord-bot/src/config.ts b/packages/discord-bot/src/config.ts index 6c9b2d2..56a524d 100644 --- a/packages/discord-bot/src/config.ts +++ b/packages/discord-bot/src/config.ts @@ -6,4 +6,5 @@ export namespace meta { GatewayIntentBits.Guilds | GatewayIntentBits.GuildMessages | GatewayIntentBits.MessageContent ); export const token = process.env.DISCORD_BOT_TOKEN as string; + export const channelId = process.env.DISCORD_FORUM_CHANNEL_ID as string; } diff --git a/packages/discord-bot/src/index.ts b/packages/discord-bot/src/index.ts index cd058f9..eb0a2c4 100644 --- a/packages/discord-bot/src/index.ts +++ b/packages/discord-bot/src/index.ts @@ -5,7 +5,7 @@ import {ForumChannel} from 'discord.js'; import {setupThreads} from './modules/thread'; import {BotContext} from './common'; -const main = async (channelId: string) => { +const main = async () => { const client = createClient({ intents: config.meta.intentsInteger, }); @@ -28,9 +28,9 @@ const main = async (channelId: string) => { } console.log(`Logged in as ${client.user.tag}`); - const channel = await client.channels.fetch(channelId); + const channel = await client.channels.fetch(config.meta.channelId); if (!(channel instanceof ForumChannel)) { - console.error(`Channel ${channelId} is not a forum!`); + console.error(`Channel ${config.meta.channelId} is not a forum!`); return; } @@ -43,4 +43,5 @@ const main = async (channelId: string) => { } // TODO load channelId from config -void main('1244285168580300904'); +// TODO add discord wizard for chatting with bot for setup (e.g. selecting forum channel ID) +void main();