Refactor bot token retrieval to use Deno.env and improve error handling
This commit is contained in:
11
src/bot.ts
11
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: {
|
||||
|
||||
Reference in New Issue
Block a user