简体   繁体   English

Node.js Discord.js UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“calculatedPosition”

[英]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 函数(如fetchMessagesmessages.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.

相关问题 discord.js UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'kickable' of undefined - discord.js UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'kickable' of undefined Discord.js | UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“部分” - Discord.js | UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'partial' of undefined UnhandledPromiseRejectionWarning:TypeError:无法读取未定义 Discord.JS 的属性“forEach” - UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'forEach' of undefined Discord.JS Discord.JS UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“startsWith” - Discord.JS UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined (node:4468) UnhandledPromiseRejectionWarning: TypeError: 无法读取未定义 Discord.js 的属性“公会” - (node:4468) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'guild' of undefined Discord.js 类型错误:无法读取未定义 Discord.js node.js v12.16.3 的属性“第一个” - TypeError: Cannot read property 'first' of undefined Discord.js node.js v12.16.3 JavaScript,Discord.js,Node.js TypeError:无法读取未定义的属性“执行” - JavaScript,Discord.js, Node.js TypeError: Cannot read property 'execute' of undefined 使用 Node.js、Mongoose 和 Discord.js 的未定义错误 [无法读取未定义的属性] - Undefined errors using Node.js, Mongoose, and Discord.js [Cannot read property of undefined] node.js/discord.js:类型错误:无法读取 null 的属性“setPresence” - node.js/discord.js: TypeError: Cannot read property 'setPresence' of null node.js discord.js 无法读取未定义的属性“发送” - node.js discord.js cannot read property 'send' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM