-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy_commands.ts
52 lines (40 loc) · 1.46 KB
/
deploy_commands.ts
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
import fs from "fs"
import Config from "./src/utils/Config"
import { REST, Routes } from "discord.js"
async function deployCommands() {
const guildCommands = []
const dmCommands = []
const commandFiles = []
commandFiles.push.apply(commandFiles, fs.readdirSync(`${__dirname}/src/commands`).filter(file => file.endsWith('.ts')))
commandFiles.push.apply(commandFiles, fs.readdirSync(`${__dirname}/src/commands`).filter(file => file.endsWith('.js')))
for (const file of commandFiles) {
const command = await import(`${__dirname}/src/commands/${file}`)
if (command.default.allowDm === true || command.default.allowDm === undefined) {
dmCommands.push(command.default.data)
}
}
for (const file of commandFiles) {
const command = await import(`${__dirname}/src/commands/${file}`)
if (!dmCommands.includes(command.default.data)) {
guildCommands.push(command.default.data)
}
}
const rest = new REST({ version: '10' }).setToken(Config.bot.token);
(async () => {
try {
console.log('Started refreshing application (/) commands.')
await rest.put(
Routes.applicationCommands(Config.bot.id),
{ body: dmCommands },
)
await rest.put(
Routes.applicationGuildCommands(Config.bot.id, Config.guild.id),
{ body: guildCommands },
)
console.log('Successfully reloaded application (/) commands.')
} catch (error) {
console.error(error)
}
})()
}
deployCommands()