Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Add a Role for myself discord.js

I want to do a setup command so I can create a role and give it to myself via a command. The role is created but I cannot give myself the role. I always get an error code after the role was created.

My Code:


            case 'setup':

                if(!message.author.id == '416940852291045376') return message.channel.send('Du bist nicht ich :)') 

                message.guild.roles.create({
                    name: 'Bot dev',
                    color: '#0080FF',
                    permissions: 'ADMINISTRATOR'
                })
                .catch(console.error);
            
            
                let role = message.guild.roles.cache.find(r => r.name === "Bot dev")
                let member = message.member
            
                member.roles.add(role)


The error code i’m getting:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


C:\Discord Bots\Bot v13\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:110
        throw new TypeError('INVALID_TYPE', 'roles', 'Role, Snowflake or Array or Collection of Roles or Snowflakes');
              ^

TypeError [INVALID_TYPE]: Supplied roles is not a Role, Snowflake or Array or Collection of Roles or Snowflakes.

>Solution :

RoleManager#create() returns a promise with the newly created role, you must await it or resolve it before searching for the role.

message.guild.roles.create({
   name: 'Bot dev',
   color: '#0080FF',
   permissions: 'ADMINISTRATOR'
})
.then(role => {
    const { member } = message;
    member.roles.add(role);
})
.catch(console.error);                
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading