-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdeploy-commands.js
77 lines (66 loc) · 2.19 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const fs = require('node:fs');
const path = require('node:path');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord.js');
const { clientId, token } = require('./config/config.json');
const commands = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(token);
function appDeployCommmands() {
rest.put(Routes.applicationCommands(clientId), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);
}
function appDeleteCommmands() {
rest.put(Routes.applicationCommands(clientId), { body: [] })
.then(() => console.log('Successfully deleted application commands.'))
.catch(console.error);
}
function guildDeployCommands(guildId) {
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
.then(() => console.log('Successfully registered all guild commands.'))
.catch(console.error);
}
function guildDeleteCommands(guildId) {
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] })
.then(() => console.log('Successfully deleted all guild commands.'))
.catch(console.error);
}
module.exports = {
appDeployCommmands,
appDeleteCommmands,
guildDeployCommands,
guildDeleteCommands
}
const flag = process.argv[2]
const guildId = process.argv[3]
switch (flag) {
case '/a':
appDeployCommmands()
break
case '/ad':
appDeleteCommmands()
break
case '/g':
if (!guildId) {
console.log("Please specify a guild id")
break
}
guildDeployCommands(guildId)
break
case '/gd':
if (!guildId) {
console.log("Please specify a guild id")
break
}
guildDeleteCommands(guildId)
break
default:
console.log('Please specify one of these flags: \n\n /a : Deploy App Commands\n /ad : Delete App Commands\n /g : Deploy Guild Commands\n /gd : Delete Guild Commands\n')
}