-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathregisterCommands.ts
More file actions
32 lines (25 loc) · 1.07 KB
/
registerCommands.ts
File metadata and controls
32 lines (25 loc) · 1.07 KB
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
// this is a script that registers the commands by sending a request to the discord api
// this should only be run whenever a command is added, removed, or its syntax is changed
// https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands
console.log('register commands!')
import '../../../configureEnv'
import type { RESTPutAPIApplicationCommandsJSONBody } from 'discord-api-types/v9'
import '../bot'
import { commands, GLOBAL_COMMAND_API_URL } from '../api/commands'
import fetch from 'node-fetch'
async function registerCommands() {
const bulkUpdate: RESTPutAPIApplicationCommandsJSONBody = commands.map(c => c.json)
await fetch(GLOBAL_COMMAND_API_URL, {
method: 'PUT',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bot ${process.env.DISCORD_TOKEN}`,
},
body: JSON.stringify(bulkUpdate),
})
console.log(
'Registered commands, Please note that you only have to run this whenever the syntax of a command is changed, i.e. not on every code change. :)'
)
process.exit(0)
}
registerCommands()