Refactor bot token retrieval to use Deno.env and improve error handling

This commit is contained in:
fzzinchemical
2025-03-25 22:44:53 +01:00
parent 9654bc0703
commit d766a99d7e

View File

@@ -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: {