Skip to content

Commit 42f587a

Browse files
authored
Add files via upload
1 parent d1731d5 commit 42f587a

File tree

2 files changed

+126
-1
lines changed

2 files changed

+126
-1
lines changed

handlers/CommandHandler.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
2+
const { Serverid, TOKEN } = require("../info.js");
3+
4+
const { Discord, Client, Intents, Collection } = require("discord.js");
5+
6+
const fs = require("fs");
7+
8+
module.exports = async function loadCommands(client) {
9+
const { REST } = require("@discordjs/rest");
10+
const { Routes } = require("discord-api-types/v9");
11+
const rest = new REST({ version: "9" }).setToken(TOKEN);
12+
13+
const ascii = require("ascii-table");
14+
const table = new ascii("CommandHandler.js");
15+
16+
table.setHeading("Command", "status", "Area");
17+
18+
const Commands = [];
19+
const commands = [];
20+
let cmdnum = 0;
21+
22+
client.commands = new Collection();
23+
24+
try {
25+
const commandFiles = fs
26+
.readdirSync("./commands")
27+
.map((folder) =>
28+
fs
29+
.readdirSync(`./commands/${folder}`)
30+
.filter((file) => file.endsWith(".js"))
31+
.map((file) => `../commands/${folder}/${file}`)
32+
)
33+
.flat();
34+
35+
if (!commandFiles == "") {
36+
for (const file of commandFiles) {
37+
const command = require(`${file}`);
38+
if (Object.keys(command).length === 0) continue;
39+
commands.push(command.data.toJSON());
40+
client.commands.set(command.data.name, command);
41+
42+
await rest.put(
43+
Routes.applicationGuildCommands(client.user.id, Serverid),
44+
{
45+
body: commands,
46+
}
47+
);
48+
if (command.global == true) {
49+
await rest.put(Routes.applicationGuildCommands(client.user.id), {
50+
body: commands,
51+
});
52+
}
53+
54+
if (command.data.name) {
55+
++cmdnum;
56+
table.addRow(
57+
command.data.name,
58+
`[ ✔ ]`,
59+
`[${command.global ? "global" : "guild"}]`
60+
);
61+
} else {
62+
table.addRow(file, `[ ✖ ]`, `[Error]`);
63+
}
64+
}
65+
}
66+
if (commandFiles == "") {
67+
table.addRow("No Cmds", `[ ✖ ]`, `[Error]`);
68+
}
69+
70+
if (!commandFiles == "") {
71+
let msg1 = "\n" + table.toString();
72+
let msg2 =
73+
"\n「 Commands 」|「 " +
74+
cmdnum +
75+
"/" +
76+
client.commands.size +
77+
" 」";
78+
console.log(msg1 + msg2);
79+
}
80+
} catch (error) {
81+
console.error(error.message);
82+
}
83+
};

handlers/EventHandler.js

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
1-
$~
1+
const { Discord, Client, Intents, Collection } = require("discord.js");
2+
3+
const fs = require("fs");
4+
5+
module.exports = function loadEvents(client) {
6+
const ascii = require("ascii-table");
7+
const table = new ascii("EventHandler.js");
8+
9+
table.setHeading("Event Name", "status");
10+
11+
let Eventnum = 0;
12+
try {
13+
const eventFiles = fs
14+
.readdirSync("./events")
15+
.filter((file) => file.endsWith(".js"));
16+
for (const file of eventFiles) {
17+
const event = require(`../events/${file}`);
18+
if (!eventFiles == "") {
19+
if (event.once) {
20+
++Eventnum;
21+
table.addRow(event.name, `[ ✔ ]`);
22+
client.once(event.name, (...args) => event.execute(...args, client));
23+
} else {
24+
++Eventnum;
25+
table.addRow(event.name, `[ ✔ ]`);
26+
client.on(event.name, (...args) => event.execute(...args, client));
27+
}
28+
}
29+
}
30+
31+
if (eventFiles == "") {
32+
table.addRow(`[ ✖ ] - No Events`);
33+
}
34+
35+
if (!eventFiles == "") {
36+
let msg1 = "\n" + table.toString();
37+
let msg2 = "\n「 Events 」|「 " + Eventnum + " 」";
38+
console.log(msg1 + msg2);
39+
}
40+
} catch (error) {
41+
console.error(error.message);
42+
}
43+
};

0 commit comments

Comments
 (0)