Discord.js bot – creating roles on setup results in RangeError

I’m making a discord bot and in !setup 1 I would like to create a few roles.
I tried this code:`

            message.channel.send(`setting up roles...`);
            guild.roles.create({
                data: {
                    name: 'Administrator', 
                    color: 'GOLD', 
                    permissions: ['ADMINISTRATOR']
                }
            });
            guild.roles.create({
                data: {
                     name: 'Moderator',
                     color: 'GREEN', 
                     permissions: {
                         KICK_MEMBER : true,
                         MANAGE_MESSAGES: true,
                         MENTION_EVERYONE: true,
                         MUTE_MEMBERS: true,
                         CHANGE_NICKNAME: true,
                         MANAGE_NICKNAMES: true,

                     }
                    }
                });
            guild.roles.create({ 
                data: { 
                    name: 'Muted',
                    permissions: {
                        SEND_MESSAGES: false,
                        ADD_REACTIONS: false,
                    }
                } 
            });

but I’m getting the following error:

RangeError [BITFIELD_INVALID]: Invalid bitfield flag or number.

Does anyone know how to fix this?

Earlier on I defined guild.

6 thoughts on “Discord.js bot – creating roles on setup results in RangeError”

  1. I found a workaround, by deleting all permissions and adding the permissions I want the roles to have, I’ve achieved the same thing.

    Here’s the code:

               guild.roles.create({data: {name: `Muted`, color: 'GREY'}});
    
    //skipped a few lines of code here for other roles I created, they follow the same method.
    
               message.channel.send('Setting permissions for Muted...').then(sentMessage =>{
                    const role = message.guild.roles.cache.find(r => r.name === "Muted");
                    role.setPermissions(0);
                    role.setPermissions(['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'CONNECT']);
                    message.channel.send('Permissions for Muted set.')
                })
    
    Reply

Leave a Comment