-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
67 lines (53 loc) · 1.98 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
//Global Stuff
const { globalStart } = require("./constants/client/start");
globalStart();
//Discord Bot
const { Client, GatewayIntentBits, Collection } = require("discord.js");
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent],
});
client.login(process.env.DISCORD_TOKEN);
module.exports = { client };
//Mongo DB
const { connectMongo } = require("./constants/client/mongo");
const MongoClient = connectMongo();
client.mongo = MongoClient.db("Pokemon").collection("Profiles");
//Imports
const fs = require("fs");
//Catch errors that might slip
process.on("uncaughtException", (error) => console.error(error));
process.on("unhandledRejection", (error) => console.error(error));
//Event Handler
const eventFiles = fs.readdirSync(__dirname + "/events").filter((file) => file.endsWith(".js"));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args, client));
} else {
client.on(event.name, (...args) => event.execute(...args, client));
}
}
//Loading Commands
loadCommands(client);
//Functions
function loadCommands(client) {
client.messageCommands = new Collection();
client.slashCommands = new Collection();
if (fs.existsSync(__dirname + "/commands/message")) {
const folder = fs.readdirSync(__dirname + "/commands/message");
for (const file of folder) {
const command = require(`./commands/message/${file}`);
client.messageCommands.set(command.name.toLowerCase(), command);
}
log(`Loaded Message Commands`);
}
if (fs.existsSync(__dirname + "/commands/interaction")) {
const folder = fs.readdirSync(__dirname + "/commands/interaction");
for (const file of folder) {
const command = require(`./commands/interaction/${file}`);
client.slashCommands.set(command.name.toLowerCase(), command);
}
log(`Loaded Slash Commands`);
}
}
client.reload = loadCommands;