[英]i keep getting an error about .position in discord.js
So i tried making a kick command in dicors.js(creating a bot).所以我尝试在 dicors.js 中创建一个 kick 命令(创建一个机器人)。 I did a little bit of research and I ended up with copying a code from stack overflow.我做了一些研究,最终从堆栈溢出中复制了一段代码。 The code was working fine but i wanned to make it so if "x" that has a lower rank tries to kick "y" which has higher rank, the bot would then send a message to "x" that he can't kick a higher rank person.代码运行良好,但我想这样做,如果具有较低等级的“x”试图踢具有较高等级的“y”,则机器人会向“x”发送一条消息,表明他不能踢级别较高的人。 (both x and y are users) (x 和 y 都是用户)
The code that i copied also has this function included and i keep getting this error我复制的代码也包含此功能,但我不断收到此错误
let authorHighestRole = msg.member.highestRole.position;
^
TypeError: Cannot read property 'position' of undefined
I searched online: nothing.我在网上搜索:没有。 I tried some stupid things like adding () to .position I searched in the Discord.js docs and still nothing.我尝试了一些愚蠢的事情,例如将 () 添加到 .position 我在 Discord.js 文档中搜索过,但仍然没有。
I came to the conclusion that the code is old.我得出的结论是代码很旧。
Here is my code这是我的代码
case 'kick' :
if(msg.channel.type === 'DM') {
msg.channel.send('This command can use only in guide');
return;
};
if(!msg.member.hasPermission('KICK_MEMBERS')) {
msg.channel.send('You have no permissions to do that');
return;
};
let mentionMember = msg.mentions.members.first();
if(!mentionMember) {
msg.channel.send('Please specify the person you want to kick!');
return;
}
if(!mentionMember.kickable) {
msg.channel.send('I can\'t kick this user!');
return
};
//Get the highest role of user for compare
let authorHighestRole = msg.member.highestRole.position;
let mentionHighestRole = mentionMember.highestRole.position;
//If mention user have same or higher role, so show this error msg
if(mentionHighestRole >= authorHighestRole) {
msg.channel.send('You can`t kick members with equal or higher position');
return;
};
mentionMember.kick()
msg.channel.send(`${mentionMember.displayName} was kicked`)
break;
Any help would be appreciated.任何帮助,将不胜感激。
member doesn't contain a property called highestRole, I believe the property you're looking for is: member.roles.heighest.成员不包含名为highestRole 的属性,我相信您要查找的属性是:member.roles.heighest。
see docs: https://discord.js.org/#/docs/main/stable/class/GuildMemberRoleManager?scrollTo=highest见文档: https : //discord.js.org/#/docs/main/stable/class/GuildMemberRoleManager? scrollTo =highest
msg.member.roles.highest.position
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.