-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.ts
106 lines (79 loc) · 2.28 KB
/
bot.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import { readFileSync } from "fs";
import {
CategoryChannel,
Client,
ClientOptions,
EmbedBuilder,
GatewayIntentBits,
Snowflake,
codeBlock,
} from "discord.js";
import { QuickDB } from "quick.db";
import loadCommands from "handlers/commandLoader";
import database from "handlers/databaseLoader";
import loadEvents from "handlers/eventLoader";
import { MessageCommand, SlashCommand } from "modules/command";
const package_json = JSON.parse(readFileSync("./package.json", "utf-8"));
export interface Config {
bot: {
token: string;
prefix: string;
owners: string[];
managers: string[];
channels: {
error: string;
};
};
}
const config = (await import("./config")).default;
interface Options extends ClientOptions {
version: string;
prefix?: string;
owners?: string[];
managers?: string[];
}
export default class Bot extends Client {
constructor(options: Options) {
super(options);
this.version = options.version;
this.prefix = options.prefix || "c!";
this.owners = options.owners || [];
this.managers = options.managers || [];
this.messageCommands = new Map();
this.slashCommands = new Map();
this.db = database;
loadEvents(this);
loadCommands(this);
}
public readonly prefix: string;
public readonly version: string;
public async reportError(error: {
stack?: string;
message: string;
}): Promise<void> {
const channel = await this.channels.fetch(config.bot.channels.error);
if (!channel || !channel.isTextBased()) return;
if (channel instanceof CategoryChannel) return;
channel.send({
embeds: [
new EmbedBuilder()
.setTitle("An error has occurred!")
.setDescription(codeBlock("js", error.stack || error.message))
.setColor("Random"),
],
});
}
public readonly owners: Snowflake[];
public readonly managers: Snowflake[];
public readonly messageCommands: Map<string, MessageCommand>;
public readonly slashCommands: Map<string, SlashCommand>;
public readonly db: QuickDB;
}
const bot = new Bot({
intents: Object.values(GatewayIntentBits) as GatewayIntentBits[],
version: package_json.version,
prefix: config.bot.prefix,
owners: config.bot.owners,
managers: config.bot.managers,
});
bot.login(config.bot.token);