[英]i keep getting an error about .position in discord.js
所以我尝试在 dicors.js 中创建一个 kick 命令(创建一个机器人)。 我做了一些研究,最终从堆栈溢出中复制了一段代码。 代码运行良好,但我想这样做,如果具有较低等级的“x”试图踢具有较高等级的“y”,则机器人会向“x”发送一条消息,表明他不能踢级别较高的人。 (x 和 y 都是用户)
我复制的代码也包含此功能,但我不断收到此错误
let authorHighestRole = msg.member.highestRole.position;
^
TypeError: Cannot read property 'position' of undefined
我在网上搜索:没有。 我尝试了一些愚蠢的事情,例如将 () 添加到 .position 我在 Discord.js 文档中搜索过,但仍然没有。
我得出的结论是代码很旧。
这是我的代码
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;
任何帮助,将不胜感激。
成员不包含名为highestRole 的属性,我相信您要查找的属性是:member.roles.heighest。
见文档: https : //discord.js.org/#/docs/main/stable/class/GuildMemberRoleManager? scrollTo =highest
msg.member.roles.highest.position
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.