-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete-commands-2.js
56 lines (44 loc) · 1.54 KB
/
delete-commands-2.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
// Using direct HTTP request to official Discord API, in case discord.js fails to delete commands
// https://discord.com/developers/docs/interactions/application-commands#get-global-application-commands
// https://discord.com/developers/docs/interactions/application-commands#updating-and-deleting-a-command
const axios = require("axios")
require('dotenv').config()
async function main () {
console.time("script_run_time")
const commandIds = await getArrayOfCommandsIds()
for (const commandId of commandIds) {
await deleteCommand(commandId)
}
}
async function getArrayOfCommandsIds() {
const url = `https://discord.com/api/v8/applications/${process.env.CLIENT_ID}/commands`
const config = {
headers: {
Authorization: `Bot ${process.env.TOKEN}`,
}
};
const response = await axios.get(url, config)
const commands = response.data
return commands.map(command => command.id)
}
async function deleteCommand(commandId) {
const url = `https://discord.com/api/v8/applications/${process.env.CLIENT_ID}/commands/${commandId}`
const config = {
headers: {
Authorization: `Bot ${process.env.TOKEN}`,
}
};
await axios.delete(url, config)
console.log(`Deleted command ${commandId}`)
}
main()
.then((resp) => {
console.log(resp)
console.log("SUCCESS!")
console.timeEnd("script_run_time")
})
.catch((e) => {
console.error(e)
console.log("FAILED!")
console.timeEnd("script_run_time")
})