[英]Node.js Discord.js UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'calculatedPosition' of undefined
I am using discord.js, I was making a ban command and I got this error: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'calculatedPosition' of undefined
我正在使用 discord.js,我正在执行禁令命令,但出现此错误:
UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'calculatedPosition' of undefined
My code is:我的代码是:
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!")
How can I fix this error?我该如何解决这个错误? I'm running the bot on Discord.js v12
我在 Discord.js v12 上运行机器人
This must be v11 code or before, check docs to update your other code, but regardless:这必须是 v11 或之前的代码,检查文档以更新您的其他代码,但无论如何:
They have changed a lot of the camelCase functions like fetchMessages
into things like messages.fetch
, might be useful to know.他们已经将很多 camelCase 函数(如
fetchMessages
为messages.fetch
之类的东西,了解可能会有用。
// 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!");
Also saw the full code and you should prob check if the user has mod/admin before you calculate all of these.还看到了完整的代码,你应该在计算所有这些之前检查用户是否有 mod/admin。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.