I have some roles in my discord server. Some is just for colors. I want to my members select the roles by their own with the command .cargo <color>
I have the code
if (command === 'cargo') {
const colors = message.guild.roles.filter(role => role.name.startsWith('#'));
if (colors.size < 1) return message.channel.send('Não há cargos nesse servidor');
const str = args.join(' ');
const role = colors.find(role => role.name.slice('#'.length).toLowerCase() === str.toLowerCase);
if(!role) return message.channel.send('Esse cargo não existe!');
try {
await message.member.removeRoles(colors);
await message.member.addRole(role);
message.channel.send(`Agora você tem o cargo ${role}!`);
}
catch (e) {
message.channel.send(`Falhei :( ${e.message}`);
}
}
but everytime I type .cargo
it's showing an error like the role doesn't exist if(!role) return message.channel.send('Esse cargo não existe!');
Errors that i noticed:
.cargo
doesn't show the server roles and return the message that the role doesn't exist
.cargo blue
return the message that the role doesn't exist
'#'.length
? That's just1
. – Joseph Webberrole.name.slice('#'.length).toLowerCase() === str.toLowerCase
, without the parenthesis. Is that a typo in your post or that's your code? If that's your code, it can't find the role becauseString.toLowerCase
is a function, try calling it and see if that works – Federico Grandi