-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.js
45 lines (41 loc) · 1.44 KB
/
deploy.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
const fs = require('fs')
require('dotenv').config()
const { PermissionsBitField } = require('discord.js')
const { Routes } = require('discord-api-types/v9')
const { REST } = require('@discordjs/rest')
const rest = new REST({
version: '9'
}).setToken(process.env.token)
module.exports = (client) => {
const slashCommands = []
fs.readdirSync('./slash/').forEach(async dir => {
const files = fs.readdirSync(`./slash/${dir}/`).filter(file => file.endsWith('.js'))
for (const file of files) {
const slashCommand = require(`./slash/${dir}/${file}`)
slashCommands.push({
name: slashCommand.name,
description: slashCommand.description,
type: slashCommand.type,
options: slashCommand.options ? slashCommand.options : null,
default_permission: slashCommand.default_permission ? slashCommand.default_permission : null,
default_member_permissions: slashCommand.default_member_permissions ? PermissionsBitField.resolve(slashCommand.default_member_permissions).toString() : null
})
if (slashCommand.name) {
client.slashCommands.set(slashCommand.name, slashCommand)
} else {
console.log(slashCommand)
}
}
});
(async () => {
try {
await rest.put(
Routes.applicationCommands(process.env.client),
{ body: slashCommands },
)
console.log(`/ commands registered`)
} catch (error) {
console.log(error)
}
})();
}