Discord js permission not working for specific commands


I have a Discord bot running on Heroku. But i have an permission issue for the following commands
Commands

As u can see in the attached picture. I don’t have permissions for the "add" command. But when i restart the bot. I get permission to use the "add" command but lose the permissions to use the other 2 commands.

Here’s my code

const Guilds = client.guilds.cache.map((guild) => guild); //Get guild info
const all_fetchedCommands = await Guilds[0].commands.fetch();
const addCommand = all_fetchedCommands.find(command => command.name === 'add');
const removeCommand = all_fetchedCommands.find(command => command.name === 'remove');
const setCompCommand = all_fetchedCommands.find(command => command.name === 'set-comp');
const addReferralCommand = all_fetchedCommands.find(command => command.name === 'add-referral');
const addCompCommand = all_fetchedCommands.find(command => command.name === 'add-comp');
const addCommandId = addCommand.permissions.commandId;
const removeCommandId = removeCommand.permissions.commandId;
const setCompCommandId = setCompCommand.permissions.commandId;
const addReferralCommandId = addReferralCommand.permissions.commandId;
const addCompCommandId = addCompCommand.permissions.commandId;

const fullPermissions = [
    {
        id: addCommandId,
        permissions: [{
            id: 'xxx', //captain role
            type: 'ROLE',
            permission: true,
        }]
    },
    {
        id: addCommandId,
        permissions: [{
            id: 'xxx', //leader role
            type: 'ROLE',
            permission: true,
        }]
    },
    {
        id: removeCommandId,
        permissions: [{
            id: 'xxx', //captain role
            type: 'ROLE',
            permission: true,
        }]
    },
    {
        id: removeCommandId,
        permissions: [{
            id: 'xxx', //leader role
            type: 'ROLE',
            permission: true,
        }]
    },
    {
        id: setCompCommandId,
        permissions: [{
            id: 'xxx', //captain role
            type: 'ROLE',
            permission: true,
        }]
    },
    {
        id: setCompCommandId,
        permissions: [{
            id: 'xxx', //leader role
            type: 'ROLE',
            permission: true,
        }]
    },
    {
        id: addReferralCommandId,
        permissions: [{
            id: 'xxx', //captain role
            type: 'ROLE',
            permission: true,
        }]
    },
    {
        id: addReferralCommandId,
        permissions: [{
            id: 'xxx', //leader role
            type: 'ROLE',
            permission: true,
        }]
    },
    {
        id: addCompCommandId,
        permissions: [{
            id: 'xxx', //captain role
            type: 'ROLE',
            permission: true,
        }]
    },
    {
        id: addCompCommandId,
        permissions: [{
            id: 'xxx', //leader role
            type: 'ROLE',
            permission: true,
        }]
    }
];

await Guilds[0].commands.permissions.set({ fullPermissions });

I have a feeling it has something to do with the word "add" since i only have issues with those commands. But i have no idea how to fix it.

Anyone able to help me out?

Source: JavaSript – Stack Overflow

November 23, 2021
Category : News
Tags: discord | discord.js | javascript | permissions

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.