aboutsummaryrefslogtreecommitdiff
path: root/deploy-command.js
blob: f4648253d98de4b54e9963ad921bb0e02109dbf5 (plain) (blame)
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
import fs, { readFileSync } from 'node:fs';
import { REST, Routes } from 'discord.js';
const { clientID, token } = JSON.parse(readFileSync('./config.json'));

const commands = [];
const commandFiles = fs.readdirSync('./Commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
  const { default: command } = await import(`./Commands/${file}`);
  commands.push(command.data.toJSON());
}

const rest = new REST().setToken(token);

// and deploy your commands!
(async() => {
  try {
    console.log(`Started refreshing ${commands.length} application (/) commands.`);

    // The put method is used to fully refresh all commands in the guild with the current set
    const data = await rest.put(
      Routes.applicationCommands(clientID),
      { body: commands }
    );

    console.log(`Successfully reloaded ${data.length} application (/) commands.`);
  } catch (error) {
    // And of course, make sure you catch and log any errors!
    console.error(error);
  }
})();