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 { createBot, Intents, startBot } from "npm:discordeno@18.0.1";
|
||||||
import * as dotenv from "jsr:@std/dotenv";
|
|
||||||
import { messagehandler } from "./messages.ts";
|
import { messagehandler } from "./messages.ts";
|
||||||
|
|
||||||
const env = dotenv.loadSync();
|
const BOT_TOKEN = Deno.env.get("BOT_TOKEN") ?? "";
|
||||||
|
if (!BOT_TOKEN) {
|
||||||
if (typeof env.BOT_TOKEN !== "string") {
|
throw new Error("BOT_TOKEN is missing!");
|
||||||
throw new Error("Bot token is required in .env file");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bot = createBot({
|
const bot = createBot({
|
||||||
token: env.BOT_TOKEN,
|
token: BOT_TOKEN,
|
||||||
intents: Intents.Guilds | Intents.GuildMessages | Intents.MessageContent |
|
intents: Intents.Guilds | Intents.GuildMessages | Intents.MessageContent |
|
||||||
Intents.DirectMessages,
|
Intents.DirectMessages,
|
||||||
events: {
|
events: {
|
||||||
|
|||||||
Reference in New Issue
Block a user