Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
Discord.js. Cannot add permissions to slash commands

Im trying to add permission to commands in such way, that only users with specific role can use it. At first im creating commands like its said in documentation.

Then Im trying to get each command and adding to them new permissions:

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);
});

But whatever I do I get this error: TypeError [INVALID_TYPE]: Supplied permissions is not an Array of ApplicationCommandPermissionData. Ive also tried running this code as shown in documentation but got same result:

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 Respuestas
Responde la pregunta

0

Changing code to this helped:

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 Denunciar

0

I dont think you can use the forEach loop like you did.

commands.permissions#set consists of an object with the id of the command you want to edit, and an array with the permissions.

So you would have to rewrite your code to this:

//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]});
});

Read more about setting permissions for slashCommands here

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda