-
Notifications
You must be signed in to change notification settings - Fork 3
/
delete-bot-commands.js
43 lines (39 loc) · 1.85 KB
/
delete-bot-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
require('dotenv').config();
const { readFileSync } = require('fs');
const { exit } = require('process');
const guildRegisterURL = 'https://discord.com/api/v10/applications/' + process.env.APPLICATION_ID + '/guilds/' + process.env.GUILD_ID + '/commands'
const appRegisterURL = 'https://discord.com/api/v10/applications/' + process.env.APPLICATION_ID + '/commands'
const headers = {
'Content-Type': 'application/json',
'Authorization': 'Bot ' + process.env.BOT_TOKEN
}
console.log('Make sure command-ids.txt is present in the current directory before you try running this.')
const mode = (process.argv.includes('-g')) && 'guild' || 'app';
if (process.argv.length < 3) console.error('No commandline arguments specified, defaulting to application.\nUse -a to specify application, and -g to specify guild.');
(mode == 'guild') && console.log(`Registering commands to guild`) || console.log(`Registering application commands, remember that Discord rate limits this`);
const URL = (mode == 'app') ? appRegisterURL : guildRegisterURL;
const commandIDs = readFileSync('./command-ids.txt', 'utf-8').split(/\s+/)
if (commandIDs[0] === '') {
console.log('It looks like there\'s no commands to delete in command-ids.txt, terminating')
exit(1);
}
commandIDs.forEach(
commandID => {
fetch(`${URL}\\${commandID}`, {
method: 'DELETE',
headers: headers
}).then(
res => {
if (res.ok) {
console.log(`Successfully deleted ${commandID}, response ${res.status} (${res.statusText})`)
} else {
console.log(`Failed to delete ${commandID}, response ${res.status} (${res.statusText})`)
};
}
).catch(
err => {
console.error(`Failed to make request for ${commandID} (${err})`)
}
)
}
)