-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
58 lines (45 loc) · 1.92 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
const fs = require("fs");
const Path = require("path");
const Discord = require("discord.js");
const client = global.client = new Discord.Client({
intents: 0,
allowedMentions: {
parse: ["users"]
}
});
client.commands = global.commands = new Discord.Collection();
const synchronizeSlashCommands = require('discord-sync-commands-v14');
const eventsRegister = () => {
let eventsDir = Path.resolve(__dirname, './events');
if (!fs.existsSync(eventsDir)) return console.log("No events dir");
fs.readdirSync(eventsDir, { encoding: "utf-8" }).filter((cmd) => cmd.split(".").pop() === "js").forEach((event) => {
let prop = require(`./events/${event}`);
if (!prop) return console.log("No props.");
console.log(`${event} was saved.`);
client.on(event.split('.')[0], prop.bind(null, client));
delete require.cache[require.resolve(`./events/${event}`)];
});
};
const commandsRegister = () => {
let commandsDir = Path.resolve(__dirname, './commands');
if (!fs.existsSync(commandsDir)) return console.log("No events dir.");
fs.readdirSync(commandsDir, { encoding: "utf-8" }).filter((cmd) => cmd.split(".").pop() === "js").forEach((command) => {
let prop = require(`./commands/${command}`);
if (!prop) return console.log("No props.");
console.log(`${command} command saved`);
client.commands.set(prop.options.name, prop);
delete require.cache[require.resolve(`./commands/${command}`)];
});
};
const slashCommandsRegister = () => {
const commands = client.commands.filter((c) => c.options);
const fetchOptions = { debug: true };
synchronizeSlashCommands(client, commands.map((c) => c.options), fetchOptions);
};
eventsRegister();
commandsRegister();
slashCommandsRegister();
client.login('a')
process.on('unhandledRejection', error => {
console.log(error);
});