This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
executable file
·67 lines (58 loc) · 2.29 KB
/
index.js
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
require("./helpers/extenders");
// This enables ComfyBot to access the extenders in any part of the codebase
const util = require("util"),
fs = require("fs"),
readdir = util.promisify(fs.readdir),
mongoose = require("mongoose");
// Some basic imports
const Comfy = require("./base/Comfy"),
client = new Comfy({ partials: ["MESSAGE", "CHANNEL", "REACTION", "GUILD_MEMBER", "USER"] });
// This requires in Comfy, which extends the base client
const init = async () => {
// Loads commands
const dirs = await readdir("./commands/");
// Reads the commands directory
dirs.forEach(async (dir) => {
const cmds = await readdir(`./commands/${dir}/`);
// gets every dir inside commands
cmds.filter(cmd => cmd.split(".").pop() === "js").forEach(cmd => {
const res = client.loadCommand(`./commands/${dir}`, cmd);
// loads each command
if (res) client.logger.log(res, "error");
// if there's an error, log it
});
});
// Loads events
const evtDirs = await readdir("./events/");
// reads the events dir
evtDirs.forEach(async dir => {
const evts = await readdir(`./events/${dir}/`);
// gets every dir inside events
evts.forEach(evt => {
const evtName = evt.split(".")[0];
// splits the event and gets first part
const event = new (require(`./events/${dir}/${evt}`))(client);
// binds client to the event
client.on(evtName, (...args) => event.run(...args));
delete require.cache[require.resolve(`./events/${dir}/${evt}`)];
// on event, call it
});
});
client.login(client.config.token);
// log in to discord
mongoose.connect(client.config.mongoDB, client.config.dbOptions).then(() => {
client.logger.log("Database connected", "log");
}).catch(err => client.logger.log("Error connecting to database. Error:" + err, "error"));
};
init();
client.on("disconnect", () => client.logger.log("Bot is disconnecting...", "warn"))
.on("reconnecting", () => client.logger.log("Bot reconnecting...", "log"))
.on("error", (e) => client.logger.log(e, "error"))
.on("warn", (info) => client.logger.log(info, "warn"));
process.on("unhandledRejection", async (err) => {
if (err.name == "DiscordAPIError") {
return client.logger.log("Discord API Error", "warn");
} else {
client.logger.log(err, "error");
}
});