Advertisement
gamodu62100

loadSlashCommands.js

Mar 20th, 2023
846
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const Discord = require("discord.js")
  2. const { REST } = require("@discordjs/rest")
  3. const { Routes } = require("discord.js")
  4. const commands = [];
  5.  
  6. module.exports = async bot => {
  7.  
  8.     let Commandes = [];
  9.  
  10.     bot.commands.forEach(async command => {
  11.    
  12.         let slashcommand = new Discord.SlashCommandBuilder()
  13.         .setName(command.name)
  14.         .setDescription(command.description)
  15.         .setDMPermission(command.dm)
  16.         .setDefaultMemberPermissions(command.permission === "Aucune" ? null : command.permission)
  17.  
  18.         if(command.options?.length >= 1){
  19.             for(let i = 0; i < command.options.length; i++){
  20.                 slashcommand[`add${command.options[i].type.slice(0, 1).tolowerCase() + command.options[i].type.slice(1, command.options[i].type.length)}Option`](option => option.setName(command.options[i].name).setDescription(command.options[i].description).setRequired(command.options[i].required))
  21.             }    
  22.         }
  23.  
  24.         await command.push(slashcommand)
  25.     })
  26.    
  27.     const rest = new REST({ version: "10" }).setToken(bot.token);
  28.  
  29.     await rest.put(Routes.applicationCommands(bot.user.id), {body: Commandes})
  30.     console.log(`les slashs commandes sont créées avec succés  !`)
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement