-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
68 lines (58 loc) · 2.15 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import * as dotenv from "dotenv";
dotenv.config();
import path from "node:path";
import { readdirSync } from "node:fs";
import { Client, Collection, GatewayIntentBits, Partials } from "discord.js";
import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";
import { getAuth, signInWithEmailAndPassword } from "firebase/auth";
import type { BotEvent, SlashCommand } from "./types.d.ts";
import * as Sentry from "@sentry/node";
Sentry.init({
dsn: process.env.SENTRY_DSN,
});
(async () => {
const app = initializeApp({
apiKey: process.env.apiKey,
authDomain: process.env.authDomain,
projectId: process.env.projectId,
});
getFirestore(app);
try {
await signInWithEmailAndPassword(getAuth(app), process.env.email!, process.env.password!);
console.log("Logged into firebase");
} catch (error) {
console.error(error);
}
const client = new Client({
partials: [Partials.Message, Partials.Channel, Partials.Reaction, Partials.ThreadMember],
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessageReactions,
],
});
client.commands = new Collection<string, SlashCommand>();
const commandFiles = readdirSync("./commands");
for (const file of commandFiles.filter((el) => path.extname(el) === ".js")) {
const filePath = "./commands/" + file;
const command = (await import(filePath)).default as SlashCommand;
if ("data" in command && "execute" in command) {
client.commands.set(command.data.name, command);
} else {
console.error(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
const eventFiles = readdirSync("./events");
for (const file of eventFiles.filter((el) => path.extname(el) === ".js")) {
const filePath = "./events/" + file;
const event = (await import(filePath)).default as BotEvent<unknown>;
if (event.once) {
client.once(event.name, (arg) => event.execute(arg));
} else {
client.on(event.name, (arg) => event.execute(arg));
}
}
client.login(process.env.token!);
})();