···1+const { REST, Routes } = require("discord.js");
2+const { client: clientId, guild: guildId, token } = process.env;
3+const fs = require("node:fs");
4+const path = require("node:path");
5+6+const commands = [];
7+// Grab all the command folders from the commands directory you created earlier
8+const foldersPath = path.join(__dirname, "commands");
9+const commandFolders = fs.readdirSync(foldersPath);
10+11+for (const folder of commandFolders) {
12+ // Grab all the command files from the commands directory you created earlier
13+ const commandsPath = path.join(foldersPath, folder);
14+ const commandFiles = fs
15+ .readdirSync(commandsPath)
16+ .filter((file) => file.endsWith(".ts") || file.endsWith(".js"));
17+ // Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
18+ for (const file of commandFiles) {
19+ const filePath = path.join(commandsPath, file);
20+ const command = require(filePath);
21+ if ("data" in command && "execute" in command) {
22+ commands.push(command.data.toJSON());
23+ } else {
24+ console.log(
25+ `[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`
26+ );
27+ }
28+ }
29+}
30+31+// Construct and prepare an instance of the REST module
32+const rest = new REST().setToken(token);
33+34+// and deploy your commands!
35+(async () => {
36+ try {
37+ console.log(
38+ `Started refreshing ${commands.length} application (/) commands.`
39+ );
40+41+ // The put method is used to fully refresh all commands in the guild with the current set
42+ const data = await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
43+ body: commands,
44+ });
45+46+ console.log(
47+ `Successfully reloaded ${data.length} application (/) commands.`
48+ );
49+ } catch (error) {
50+ // And of course, make sure you catch and log any errors!
51+ console.error(error);
52+ process.stdout.write(JSON.stringify(error) + "\n");
53+ }
54+})();