[英]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.