-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
93 lines (78 loc) · 2.86 KB
/
index.js
File metadata and controls
93 lines (78 loc) · 2.86 KB
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
const { Client, GatewayIntentBits, Collection, EmbedBuilder, time } = require("discord.js");
const fs = require("node:fs");
const path = require("node:path");
const mongoose = require("mongoose");
const package = require("./package.json");
require("dotenv").config();
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent
]
});
client.commands = new Collection();
client.version = package.version;
// Commands Loading
const commandsFolder = path.join(__dirname, "commands");
const subFolders = fs.readdirSync(commandsFolder);
for (const folder of subFolders) {
const folderPath = path.join(commandsFolder, folder);
const commands = fs.readdirSync(folderPath);
for (const commandFile of commands) {
const commandPath = path.join(folderPath, commandFile);
const command = require(commandPath);
if ("data" in command && "execute" in command && "category" in command) {
client.commands.set(command.data.name, command);
} else {
console.log(
`[WARNING] The command at ${commandPath} is missing a required \"data\", \"execute\", or \"category\" property.`
);
}
}
}
// Events Loading
const eventsFolder = path.join(__dirname, "events");
const events = fs.readdirSync(eventsFolder).filter((file) => file.endsWith(".js"));
for (const eventFile of events) {
const eventPath = path.join(eventsFolder, eventFile);
const event = require(eventPath);
if (event.enabled == false) {
console.log(`${eventFile} event is disabled.`);
continue;
}
if (event.name && event.listener) {
client.on(event.name, async (...args) => {
try {
await event.listener(client, ...args);
} catch (error) {
console.log(error);
const channel = client.channels.cache.get("1204677789421150208");
channel.send({
embeds: [
new EmbedBuilder()
.setTitle("Event Error!")
.setColor(process.env.BOT_COLOR)
.setDescription(
`Error for event ${eventFile} at ${time(Date.now())}\n\n\`\`\`\n${
error.stack
}\n\`\`\``
)
]
});
}
});
} else {
console.log("One or more fields missing from event " + eventPath);
}
}
// Logging in and mongo auth
mongoose
.connect(process.env.MONGO_URI, {
dbName: process.env.DATABASE_NAME
})
.then(() => {
console.log("Mongoose Connected!");
client.login(process.env.TOKEN);
});