This repository has been archived by the owner on Oct 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-commands.js
62 lines (50 loc) · 1.99 KB
/
deploy-commands.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('node:fs');
const { REST, Routes, Client } = require('discord.js');
require('dotenv').config();
const client = new Client({ intents: ['Guilds','GuildMembers'] });
const commands = [];
//Grabs all command files from the directory
const commandFiles = fs.readdirSync('./commands/utility').filter(file => file.endsWith('.js'));
//Grabs the SlashcommandbuildertoJSon output of each command's data for deployment
for (const file of commandFiles) {
const command = require(`./commands/utility/${file}`);
commands.push(command.data.toJSON());
}
//Contruct and prepare an instance of the rest module
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// Deploy to specific guild
// const data = await rest.put(
// Routes.applicationGuildCommands(Client id here, Guild id here),
// { body: commands },
// );
// Globally deploys commands
const data = await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})();
client.on('guildCreate', async (guild) => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
// Deploy to specific guild
// const data = await rest.put(
// Routes.applicationGuildCommands(Client id here, Guild id here),
// { body: commands },
// );
// Globally deploys commands
const data = await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
})