问题描述
我正在尝试创建一个可以给您提供命令的命令!role {pronoun}.如果代词存在,它将为您提供现有角色,但如果代词不存在,它将为您提供已经扮演的角色.每次我运行命令时,都会收到一条错误消息,提示类型错误:fn.bind不是函数".我不知道为什么,如果你们所有人都能帮助我,那真是太好了.
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;
}
})
推荐答案
这是由 message.member.roles.cache.find("name","Member")
引起的. .find()
方法接受一个函数作为其第一个参数(您提供了一个字符串),并将用作 this
的值作为其第二个参数(您提供了另一个字符串).
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).
您可以通过检查 name
属性是否等于"Member"
:
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:您的代码中可能还有其他错误,但是 TypeError:fn.bind不是函数
可以解决此问题.
PS: Chances are there are other errors in your code but TypeError: fn.bind is not a function
can be solved by this.
这篇关于discord.js的fn.bind错误代码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!