-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbot.js
73 lines (66 loc) · 1.95 KB
/
bot.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
68
69
70
71
72
73
require("dotenv").config();
const moment = require("moment");
const Logger = require("./utils/logger");
const {
Client,
GatewayIntentBits,
Partials,
Collection,
} = require("discord.js");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildEmojisAndStickers,
],
partials: [
Partials.Channel,
Partials.Message,
Partials.User,
Partials.GuildMember,
Partials.Reaction,
],
});
const config = require("./config.json");
const dbManager = require("./utils/db/manager");
client.commands = new Collection();
client.aliases = new Collection();
client.slashCommands = new Collection();
client.buttons = new Collection();
client.select_menus = new Collection();
client.prefix = config["default"].server.prefix;
client.config = config;
client.models = require("./utils/db/models");
client.logger = new Logger(`./log/${moment().format("YYYY-MM-DD")}.log`);
client.get = dbManager.get;
client.logger
.init()
.then(async () => {
if (config.database) {
await dbManager.connect(client);
}
const handlers = ["command", "slashCommand", "events", "component"];
for (const handler of handlers) {
try {
require(`./handlers/${handler}`)(client);
client.logger.info(`[MAIN] Called ${handler} handler`);
} catch (err) {
client.logger.error(
`[MAIN] Error calling ${handler} handler: ${err.message}`
);
}
}
await client.login(process.env.TOKEN);
client.logger.info("[MAIN] Client logged in");
})
.catch((err) => {
console.error(`[MAIN] Error initializing bot: ${err.stack}`);
client.logger.error(`[MAIN] Error initializing bot: ${err.message}`);
process.exit(1);
});
module.exports = client;