Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda