我正在开发一个 discord.js bot,它给了我一个 TypeError,但我不知道为什么。 代码:
module.exports = {
name: 'kick',
description: 'Tag a member and kick them',
execute(message) {
if(!message.member.hasPermission('KICK_MEMBERS')) {
message.channel.send("You're not an admin lmaooo")
return;
};
let mentionMember = message.mentions.members.first();
if(!mentionMember){
message.channel.send("Who do you want me to kick :smiling_imp:")
return;
}
let authorHighestRole = message.member.highestRole.position;
let mentionHighestRole = mentionMember.highestRole.position;
if(mentionHighestRole >= authorHighesrRole) {
message.channel.send("I can't kick him hes to op :tired_fac:")
return;
};
if(!mentionMember.kickable){
message.channel.send("I have no perms cant kick him lol")
};
mentionMember.kick()
.then(() => console.log(`Kicked ${member.displayName}`))
.catch(console.error);
},
};
错误:类型错误:无法读取未定义的属性“位置”
答案 0 :(得分:0)
您需要指定要编码的内容。
Node.js 通常会提供发生错误的行。
检查if (mentionHighestRole >= authorHighesrRole) {
它可能应该是 authorHighestRole
。
如果这不能解决问题,那么可能是 if 语句本身,因为该语句对我来说没有意义。
编辑:您的 authorHighestRole
也应该是 let authorHighestRole = message.author.highestRole.position
。