Files
dc-bot/src/index.ts
Space-Banane e1300a98b3
All checks were successful
CI / build (push) Successful in 10s
ran prettier lol
2026-02-22 15:31:37 +01:00

62 lines
1.4 KiB
TypeScript

import {
Client,
Events,
GatewayIntentBits,
Message,
Partials,
} from "discord.js";
import dotenv from "dotenv";
import path from "path";
import loadModulesFromDir from "./lib/loadStartupHandlers";
import * as mongoDB from "mongodb";
import { env } from "process";
import webserver from "./webserver";
dotenv.config();
const dbclient: mongoDB.MongoClient = new mongoDB.MongoClient(env.MONGO_DB!);
const db: mongoDB.Db = dbclient.db(env.DB_NAME!);
export { db, dbclient };
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
],
partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction,
Partials.User,
],
});
let readyClient: typeof client | null = null;
client.once(Events.ClientReady, async (rc) => {
readyClient = rc;
console.log(`Logged in as ${rc.user.tag}`);
const dirs = [
path.join(__dirname, "commands"), // load commands first
path.join(__dirname, "handlers"),
path.join(__dirname, "listeners"),
];
for (const dir of dirs) {
await loadModulesFromDir(dir, client);
}
});
// Start webserver in the background
webserver().catch(console.error);
// Exports
export { client, readyClient };
client.login(process.env.DISCORD_TOKEN);