-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeploy.js
36 lines (29 loc) · 1.29 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
const { REST, Routes } = require('discord.js');
const { appID, testingServerID, token, commandsDir } = require("./config/config.js")
const fs = require('node:fs');
const path = require('node:path');
const commands = [];
const folderPath = path.join(__dirname, commandsDir);
const commandFiles = fs.readdirSync(folderPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(folderPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.warn(`The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
const rest = new REST().setToken(token);
(async () => {
console.log(`Started modifying commands…`);
let data = await rest.put(
process.argv[2]?.includes("p") ?
Routes.applicationCommands(appID) :
Routes.applicationGuildCommands(appID, testingServerID), { body: process.argv[2]?.includes("r") ? [] : commands }
).catch(console.error);
const statusMsg = process.argv[2]?.includes("r") ?
`Successfully deleted all ${process.argv[2]?.includes("p") ? "" : "guild "}commands.` :
`Successfully reloaded ${data.length} ${process.argv[2]?.includes("p") ? "application" : "guild"} commands.`
console.log(statusMsg)
})();