Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
Discord.js. No se pueden agregar permisos a los comandos de barra

Estoy tratando de agregar permiso a los comandos de tal manera que solo los usuarios con un rol específico puedan usarlo. Al principio estoy creando comandos como se dice en la documentación.

Luego estoy tratando de obtener cada comando y agregarles nuevos permisos:

 await commands.forEach(command => { const permissions2 = [ { id: guild.roles.everyone.id, type: 'ROLE', permission: false, } ]; const permissions1 = [ { id: botRole.id, type: 'ROLE', permission: true, }, ]; console.log(`Changing command ${command.id}`); command.permissions.add(permissions2); command.permissions.add(permissions1); });

Pero haga lo que haga, aparece este error: TypeError [INVALID_TYPE]: Supplied permissions is not an Array of ApplicationCommandPermissionData. También intenté ejecutar este código como se muestra en la documentación, pero obtuve el mismo resultado:

 await commands.forEach(command => { ... console.log(`Changing command ${command.id}`); command.permissions.add({permissions2}); command.permissions.add({permissions1}); });
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Cambiar el código a esto ayudó:

 const permissions2 = { id: guild.roles.everyone.id, type: 'ROLE', permission: false, }; const permissions1 = { id: botRole.id, type: 'ROLE', permission: true, }; let commandsList = await guild.commands.fetch(); await commandsList.forEach(slashCommand => { console.log(`Changing command ${slashCommand.id}`); //set the permissions for each slashCommand guild.commands.permissions.add({ command: slashCommand.id, permissions: [permissions1, permissions2] }); });
about 4 years ago · Juan Pablo Isaza Report

0

No creo que puedas usar el bucle forEach como lo hiciste.

commands.permissions#set consta de un objeto con la identificación del comando que desea editar y una matriz con los permisos.

Así que tendrías que volver a escribir tu código a esto:

 //create the permissions objects const permissions2 = { id: guild.roles.everyone.id, type: 'ROLE', permission: false, }; const permissions1 = { id: botRole.id, type: 'ROLE', permission: true, }; //loop through all the slashCommands await commands.forEach(slashCommand => { console.log(`Changing command ${slashCommand.id}`); //set the permissions for each slashCommand client.application.commands.permissions.set({command: slashCommand.id, permissions: [permissions1, permissions2]}); });

Lea más sobre la configuración de permisos para slashCommands aquí

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!