-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
loader.js
67 lines (58 loc) · 2.29 KB
/
loader.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
const { readdirSync } = require("fs");
const { Collection } = require("discord.js");
const { useMainPlayer } = require("discord-player");
client.commands = new Collection();
const commandsArray = [];
const player = useMainPlayer();
const { Translate, GetTranslationModule } = require("./process_tools");
const discordEvents = readdirSync("./events/Discord/").filter((file) =>
file.endsWith(".js")
);
const playerEvents = readdirSync("./events/Player/").filter((file) =>
file.endsWith(".js")
);
GetTranslationModule().then(() => {
console.log("| Translation Module Loaded |");
for (const file of discordEvents) {
const DiscordEvent = require(`./events/Discord/${file}`);
const txtEvent = `< -> > [Loaded Discord Event] <${file.split(".")[0]}>`;
parseLog(txtEvent);
client.on(file.split(".")[0], DiscordEvent.bind(null, client));
delete require.cache[require.resolve(`./events/Discord/${file}`)];
}
for (const file of playerEvents) {
const PlayerEvent = require(`./events/Player/${file}`);
const txtEvent = `< -> > [Loaded Player Event] <${file.split(".")[0]}>`;
parseLog(txtEvent);
player.events.on(file.split(".")[0], PlayerEvent.bind(null));
delete require.cache[require.resolve(`./events/Player/${file}`)];
}
readdirSync("./commands/").forEach((dirs) => {
const commands = readdirSync(`./commands/${dirs}`).filter((files) =>
files.endsWith(".js")
);
for (const file of commands) {
const command = require(`./commands/${dirs}/${file}`);
if (command.name && command.description) {
commandsArray.push(command);
const txtEvent = `< -> > [Loaded Command] <${command.name.toLowerCase()}>`;
parseLog(txtEvent);
client.commands.set(command.name.toLowerCase(), command);
delete require.cache[require.resolve(`./commands/${dirs}/${file}`)];
} else {
const txtEvent = `< -> > [Failed Command] <${command.name.toLowerCase()}>`;
parseLog(txtEvent);}
}
});
client.on("ready", (client) => {
if (client.config.app.global)
client.application.commands.set(commandsArray);
else
client.guilds.cache
.get(client.config.app.guild)
.commands.set(commandsArray);
});
async function parseLog(txtEvent) {
console.log(await Translate(txtEvent, null));
}
});