-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
145 lines (116 loc) · 4.6 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const dotenv = require("dotenv");
dotenv.config();
const { Client, Collection, GatewayIntentBits } = require("discord.js");
const fs = require("node:fs");
const path = require("node:path");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildInvites,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.DirectMessages,
],
});
client.commands = new Collection();
client.buttons = new Collection();
client.modals = new Collection();
client.selectMenus = new Collection();
const commandsPath = path.join(__dirname, "src/commands");
const commandFolders = fs.readdirSync(commandsPath);
for (const commandFolder of commandFolders) {
const commandsPath1 = path.join(commandsPath, commandFolder);
const commandFiles = fs.readdirSync(commandsPath1).filter(
(file) => file.endsWith(".js"),
);
for (const file of commandFiles) {
const filePath = path.join(commandsPath1, file);
const command = require(filePath);
if ("data" in command && "execute" in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
const eventsPath = path.join(__dirname, "src/events");
const eventFolders = fs.readdirSync(eventsPath);
for (const eventFolder of eventFolders) {
const eventPath = path.join(eventsPath, eventFolder);
const eventFiles = fs.readdirSync(eventPath).filter(
(file) => file.endsWith(".js"),
);
for (const file of eventFiles) {
const filePath = path.join(eventPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
}
const buttonsPath = path.join(__dirname, "src/buttons");
const buttonsFolders = fs.readdirSync(buttonsPath);
for (const buttonsFolder of buttonsFolders) {
const buttonsPath1 = path.join(buttonsPath, buttonsFolder);
const buttonFiles = fs.readdirSync(buttonsPath1).filter(
(file) => file.endsWith(".js"),
);
for (const file of buttonFiles) {
const filePath = path.join(buttonsPath1, file);
const button = require(filePath);
if ("data" in button && "execute" in button) {
client.buttons.set(button.data.name, button);
} else {
console.log(`[WARNING] The button at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
const modalsPath = path.join(__dirname, "src/modals");
const modalsFolders = fs.readdirSync(modalsPath);
for (const modalsFolder of modalsFolders) {
const modalsPath1 = path.join(modalsPath, modalsFolder);
const modalFiles = fs.readdirSync(modalsPath1).filter(
(file) => file.endsWith(".js"),
);
for (const file of modalFiles) {
const filePath = path.join(modalsPath1, file);
const modal = require(filePath);
if ("data" in modal && "execute" in modal) {
client.modals.set(modal.data.name, modal);
} else {
console.log(`[WARNING] The modal at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
const selectMenusPath = path.join(__dirname, "src/selectMenus");
const selectMenusFolders = fs.readdirSync(selectMenusPath);
for (const selectMenusFolder of selectMenusFolders) {
const selectMenusPath1 = path.join(selectMenusPath, selectMenusFolder);
const selectMenuFiles = fs.readdirSync(selectMenusPath1).filter(
(file) => file.endsWith(".js"),
);
for (const file of selectMenuFiles) {
const filePath = path.join(selectMenusPath1, file);
const selectMenu = require(filePath);
if ("data" in selectMenu && "execute" in selectMenu) {
client.selectMenus.set(selectMenu.data.name, selectMenu);
} else {
console.log(`[WARNING] The selectMenu at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
process.on("exit", code => {
console.log(`Exiting with code ${code}`);
});
process.on("uncaughtException", (err, origin) => {
console.error(`Uncaught exception: ${err}`);
console.error(`Origin: ${origin}`);
});
process.on("unhandledRejection", (reason, promise) => {
console.error(`Unhandled rejection: ${reason}`);
console.error(`Promise: ${promise}`);
});
process.on("warning", (...args) => console.log(...args));
client.login(process.env.TOKEN);