This repository has been archived by the owner on May 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
62 lines (52 loc) · 1.9 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
const fs = require('fs');
const { Client, Collection, Intents } = require('discord.js');
/**@type {import('discord.js').Client} */
const client = new Client({ allowedMentions: false, intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
client.once('ready', () => {
// Do for each guild, just in case there is more than one and to automatically fetch it
client.guilds.cache.forEach(guild => {
// Purposefully not async
guild.commands.fetch().then(() => {
guild.commands.cache.forEach(command => {
// Check if it exists in the list of commands
if (!client.commands.has(command.name)) {
// Delete if there is no file for it
command.delete().catch(err => {
console.log(err);
});
}
});
for (const cmdName of client.commands.keys()) {
// For all the commands, send the JSON over to the API
// According to Discord's documentation, commands that exist will simply be updated
guild.commands.create(client.commands.get(cmdName).data.toJSON()).catch((err) => {
console.log(err);
})
}
});
});
// temp, only needed to remove global commands for the per commands
client.application.commands.fetch().then(() => {
client.application.commands.cache.forEach(cmd => {
cmd.delete().catch(err => {
console.log(err);
})
})
})
});
const eventFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.login(process.env.TOKEN_DISCORD);