Node.js Discord.js UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ calculatedPosition” [英] Node.js Discord.js UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'calculatedPosition' of undefined
问题描述
我正在使用discord.js,正在执行ban命令,但出现以下错误: UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性'calculatedPosition'
I am using discord.js, I was making a ban command and I got this error: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'calculatedPosition' of undefined
我的代码是:
let banUser = message.guild.member(message.mentions.users.first())
let bannerHighRole = message.member.highestRole.calculatedPosition;
let getBannedHighRole = banUser.highestRole.calculatedPosition;
if (bannerHighRole < getBannedHighRole) return message.reply("You cannot ban users that have higher roles than you!")
if (bannerHighRole = getBannedHighRole) return message.reply("You cannot ban users that have same highest role!")
如何解决此错误?
我正在Discord.js v12上运行机器人
How can I fix this error? I'm running the bot on Discord.js v12
推荐答案
这必须是v11代码或之前的版本,请检查文档来更新您的其他代码,但无论如何:
This must be v11 code or before, check docs to update your other code, but regardless:
他们已将诸如 fetchMessages
之类的很多camelCase函数更改为东西像 messages.fetch
之类的信息,可能会很有用。
They have changed a lot of the camelCase functions like fetchMessages
into things like messages.fetch
, might be useful to know.
// you can use message.mentions.members instead of converting a user
let banUser = message.mentions.members.first();
let bannerHighRole = message.member.roles.highest.position;
let getBannedHighRole = banUser.roles.highest.position;
if (bannerHighRole < getBannedHighRole) return message.reply("You cannot ban users that have higher roles than you!");
//you had x = y, which is an assignment
if (bannerHighRole === getBannedHighRole) return message.reply("You cannot ban users that have same highest role!");
也看到了完整的代码,在计算所有值之前,应先检查用户是否具有mod / admin其中。
Also saw the full code and you should prob check if the user has mod/admin before you calculate all of these.
这篇关于Node.js Discord.js UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“ calculatedPosition”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!