mekasu0124

Untitled

Sep 17th, 2024
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. const { REST, Routes } = require('discord.js');
  3. const { token, guild_id, client_id } = require('./config.json');
  4. const fs = require('node:fs');
  5. const path = require('node:path');
  6.  
  7. const commands = [];
  8.  
  9. const foldersPath = path.join(__dirname, 'commands');
  10. const commandFolders = fs.readdirSync(foldersPath);
  11.  
  12. for (const folder of commandFolders) {
  13.   const commandsPath = path.join(foldersPath, folder);
  14.   const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
  15.  
  16.   for (const file of commandFiles) {
  17.     const filePath = path.join(commandsPath, file);
  18.     const command = require(filePath);
  19.     if ('data' in command && 'execute' in command) {
  20.       commands.push(command.data.toJSON());
  21.     } else {
  22.       console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
  23.     }
  24.   }
  25. }
  26.  
  27. const rest = new REST().setToken(token);
  28.  
  29. (async () => {
  30.   try {
  31.     console.log(`Started refreshing ${commands.length} application (/) commands.`);
  32.  
  33.     const data = await rest.put(
  34.       Routes.applicationGuildCommands(client_id, guild_id),
  35.       { body: commands },
  36.     );
  37.  
  38.     console.log(`Successfully reloaded ${data.length} application (/) commands.`);
  39.   } catch (error) {
  40.     console.error(error);
  41.   }
  42. })();
Advertisement
Add Comment
Please, Sign In to add comment