简体   繁体   中英

What is the fn.bind Error code for discord.js?

I'm trying to make a command that gives you on the command, .role {pronoun}, If the pronoun exists then it will give you the existing role. but if it doesn't exist it will give you the role already made: Each time I run the command though I get an error that says "Type Error. fn.bind is not a function", I have no clue why. if y'all could help me out that would be amazing.

client.on('message', async message => {
        var input = (message.content.substr(12))
        var roleName = (message.content.substr(12));
        var role = message.guild.roles.cache.find(r => r.name == roleName);
        if(!role){
            if (message.member.roles.cache.find("name", "Member")){ 
            message.channel.sendMessage('Sorry you already have a pronoun');
            return;
            }
            else if (input === ""){
            message.channel.sendMessage('Please Enter a Valid Pronoun Name');
            return;
            }
            else{
            var pronounName = message.guild.roles.find(role => role.name === "Member");
            message.member.guild.createRole({
                name: message.content.substr(12),
        }).then(function(role)
        {
            message.member.addRole(role);
            message.member.addRole(pronounName);
            message.channel.sendMessage('You have created the pronoun: ' + role);
        });
            }   
        }else{
            message.channel.sendMessage('That Pronoun Already Exists!');
            return;
        }
    })

It's caused by message.member.roles.cache.find("name", "Member") . The .find() method accepts a function as its first argument (you provided a string) and the value to use as this as its second argument (you provided another string).

You could find a role by checking if the name property is equal to "Member" :

message.member.roles.cache.find((role) => role.name === 'Member')

PS: Chances are there are other errors in your code but TypeError: fn.bind is not a function can be solved by this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM