-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
96 lines (80 loc) · 2.97 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
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
const { Client, GatewayIntentBits, Collection, Events, Partials } = require("discord.js");
const { Users, userManager, itemHandler, achievementHunter, collectionOverseer, } = require("./util/userManager");
const { guildOverseer, Guilds } = require("./util/guildOverseer");
const interactionEvents = require('./events/interactionEvents.js');
const messageEvents = require('./events/messageEvents.js');
const timeEvents = require('./events/timeEvents.js');
const util = require("./util/util");
const fs = require("fs");
require("winston/lib/winston/config");
//* setup bot client
const client = new Client({
intents: [
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.DirectMessages,
],
partials: [Partials.Channel]
});
client.emojiCharacters = require("./data/emojiCharacters");
client.logger = require("./util/logger");
//* Get enviroment token
require("dotenv").config();
if (process.argv.includes("-t") || process.argv.includes("-test")) client.login(process.env.TESTTOKEN);
else client.login(process.env.TOKEN);
//* Initialize client
client.once("ready", async () => {
let memberTotal = 0;
client.guilds.cache.forEach((g) => {
if (!isNaN(memberTotal) && g.id != 264445053596991498) {
memberTotal += Number(g.memberCount);
}
});
//* Start time based Events
timeEvents.execute(client);
//* Load in database
try {
const storedUsers = await Users.findAll();
storedUsers.forEach((b) => userManager.set(b.user_id, b));
const storedGuilds = await Guilds.findAll();
storedGuilds.forEach((b) => guildOverseer.set(b.guild_id, b));
}
catch (e) {
client.logger.error(e);
}
client.guildOverseer = guildOverseer;
client.userManager = userManager;
client.itemHandler = itemHandler;
client.achievementHunter = achievementHunter;
client.collectionOverseer = collectionOverseer;
client.util = util;
client.logger.info(`Logged in as ${client.user.tag}!`);
});
// ? Bad error handling
client.on("warn", (e) => console.log(e));
client.on("error", (e) => console.log(e));
process.on("warning", (e) => console.log(e));
process.on("unhandledRejection", (e) => console.log(e));
process.on("TypeError", (e) => console.log(e));
process.on("uncaughtException", (e) => console.log(e));
//* Gather all commands
client.commands = new Collection();
const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
}
//* Respond to messages
client.on(Events.MessageCreate, async (message) => {
messageEvents.message(message, client);
});
//* Handle interactions
client.on(Events.InteractionCreate, async (interaction) => {
interactionEvents.interaction(interaction, client);
});