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

155
Views
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 answers
Answer question

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 Report

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 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!