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:
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);