我正在使用discord.js,正在执行ban命令,但出现以下错误: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上运行该机器人
答案 0 :(得分:0)
这必须是v11或更高版本的代码,请检查文档以更新您的其他代码,但无论如何:
他们已经将很多fetchMessages
之类的camelCase函数更改为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!");
还看到了完整的代码,在计算所有这些代码之前,您应该检查用户是否具有mod / admin。