-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy_commands.js
39 lines (34 loc) · 1.46 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
31
32
33
34
35
36
37
38
39
const fs = require("fs");
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const commands = [];
//const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
const cmdPaths = require("./cmdPaths.js").data;
const commandFiles = [];
for (let i = 0; i < cmdPaths.length; i++) {
commandFiles[i] = fs.readdirSync(cmdPaths[i]).filter(file => file.endsWith(".js")); // fs.readdirSync() 的结果是个数组,所以 commandFiles是个二维数组
for (let j = 0; j < commandFiles[i].length; j++) {
commandFiles[i][j] = cmdPaths[i] + "/" + commandFiles[i][j];
}
}
//console.log(commandFiles);
for (const fileArray of commandFiles) {
for (const file of fileArray) {
console.log(file);
let command = require(`./${file}`);
commands.push(command.data.toJSON());
// if any ‘aka' name exists
if (command.akaNames != null && command.akaNames !== []) {
for (let i = 0; i < command.akaNames.length; i++) {
let akaData = command.data;
akaData.name = command.akaNames[i];
commands.push(akaData.toJSON());
}
}
}
}
const rest = new REST({ version: '10' }).setToken(token);
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands })
.then(() => console.log('Successfully registered application commands.'))
.catch(console.error);