-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.js
64 lines (59 loc) · 2.12 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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import fs from "node:fs";
import "dotenv/config";
import { REST, Routes, SlashCommandBuilder } from "discord.js";
const developping = ["reload", "eval", "rocketleague"];
let commands = [];
const foldersPath = new URL("commands", import.meta.url);
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = new URL(`${foldersPath}/${folder}`, import.meta.url);
const commandFiles = fs
.readdirSync(commandsPath)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const filePath = new URL(`${commandsPath}/${file}`, import.meta.url);
await import(filePath).then((command) => {
if ("data" in command && "execute" in command) {
console.log(
`[REUSSI] Le fichier ${filePath} a bien été pris en compte`
);
commands.push(command.data.toJSON());
} else {
console.log(
`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
);
}
});
}
}
const rest = new REST().setToken(process.env.DISCORD_TOKEN);
// and deploy your commands!
commands = commands.filter((element) => !developping.includes(element.name));
await (async () => {
try {
console.log(
`[REFRESH ALL] Le rafraichissement de ${commands.length} application (/) a commencé.`
);
// for global commands
await rest
.put(Routes.applicationCommands(process.env.APP_ID), { body: [] })
.then(() =>
console.log(
`[REFRESH ALL] Suppression de toutes les commandes déployées terminée`
)
)
.catch(console.error);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationCommands(process.env.APP_ID),
{ body: commands }
);
console.log(
`[REFRESH ALL] Le rafraichissement de ${data.length} applications a réussi.`
);
} catch (error) {
// And of course, make sure you catch and log any errors!
console.error(error);
}
return;
})();