-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-commands.js
30 lines (24 loc) · 1.17 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
const fs = require("fs")
const { REST } = require("@discordjs/rest")
const { Routes } = require("discord-api-types/v9")
const configuration = require("./config.json")
const commands = []
const gcommands = []
const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"))
for (const file of commandFiles) {
const command = require(`./commands/${file}`)
if (configuration.guildOnlyCommandFiles.indexOf(file) === -1) {
commands.push(command.data.toJSON())
console.log(`Indexed ${file} as a global command.`)
} else {
gcommands.push(command.data.toJSON())
console.log(`Indexed ${file} as a debug-guild-only command.`)
}
}
const rest = new REST({ version: "9" }).setToken(configuration.authToken)
rest.put(Routes.applicationGuildCommands(configuration.clientId, configuration.guildId), { body: gcommands })
.then(() => console.log("Successfully registered guild-only commands."))
.catch(console.error)
rest.put(Routes.applicationCommands(configuration.clientId), { body: commands })
.then(() => console.log("Successfully registered global commands. expect them to start working in an hour (or whenever Discord's API starts working."))
.catch(console.error)