无法从命令中找到角色

Cannot find role from command

我在我的 discord 服务器中有一些角色。有些只是为了颜色。我想让我的成员 select 使用命令 .cargo <color>

自己的角色

我有密码

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}`);
    }
}

但每次我输入 .cargo 它都会显示错误,例如角色不存在 if(!role) return message.channel.send('Esse cargo não existe!');

我注意到的错误:

.cargo 不显示服务器角色和 return 角色不存在的消息

.cargo blue return 角色不存在的消息

[来自评论的解决方案]
在第 5 行,你写了 role.name.slice('#'.length).toLowerCase() === str.toLowerCase,没有括号。如果那是你的代码,它找不到角色,因为 String.toLowerCase 是一个函数,尝试调用它看看是否有效。