From d766a99d7ecadc14cfeab773f3be304337407365 Mon Sep 17 00:00:00 2001 From: fzzinchemical Date: Tue, 25 Mar 2025 22:44:53 +0100 Subject: [PATCH] Refactor bot token retrieval to use Deno.env and improve error handling --- src/bot.ts | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 8a4e281..26b8d52 100755 --- a/src/bot.ts +++ b/src/bot.ts @@ -1,15 +1,12 @@ import { createBot, Intents, startBot } from "npm:discordeno@18.0.1"; -import * as dotenv from "jsr:@std/dotenv"; import { messagehandler } from "./messages.ts"; -const env = dotenv.loadSync(); - -if (typeof env.BOT_TOKEN !== "string") { - throw new Error("Bot token is required in .env file"); +const BOT_TOKEN = Deno.env.get("BOT_TOKEN") ?? ""; +if (!BOT_TOKEN) { + throw new Error("BOT_TOKEN is missing!"); } - const bot = createBot({ - token: env.BOT_TOKEN, + token: BOT_TOKEN, intents: Intents.Guilds | Intents.GuildMessages | Intents.MessageContent | Intents.DirectMessages, events: {