53 lines
1.3 KiB
TypeScript
53 lines
1.3 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); |