简体   繁体   English

discord.js 的 fn.bind 错误代码是什么?

[英]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.我正在尝试创建一个命令,让您获得命令 .role {pronoun},如果代词存在,那么它将为您提供现有角色。 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.但如果它不存在,它将为您提供已经完成的角色:每次运行命令时都会收到一条错误消息,显示“类型错误。fn.bind 不是函数”,但我不知道为什么。 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") .这是由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). .find()方法接受 function 作为其第一个参数(您提供了一个字符串)和用作this作为其第二个参数的值(您提供了另一个字符串)。

You could find a role by checking if the name property is equal to "Member" :您可以通过检查name属性是否等于"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. PS:您的代码中可能存在其他错误,但TypeError: fn.bind is not a function可以通过此解决。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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