.permission.has() discord.js v12 - 无法读取未定义的 属性 'permissions'

.permission.has() discord.js v12 - Cannot read property 'permissions' of undefined

我在为 MANAGE_MESSAGES 能够说 'badword' 的人编写我的机器人时遇到了问题。这是我的代码:

const Discord = require('discord.js')
const bot = new Discord.Client()
const token = process.env.DISCORD_TOKEN

let set = new Set(['badword'])
bot.on('message', msg => {
  if (msg.author.bot) {
    return
  }
  let wordArray = msg.content.split(' ')
  if (!msg.member.hasPermission('MANAGE_MESSAGES')) {
  for(var i = 0; i < wordArray.length; i++) {
    if(set.has(wordArray[i].toLowerCase())) {
      msg.delete()
      msg.channel.send(`${msg.author.username}, you said a bad word.`)
      break
    }
    console.log('message filtered')
  }   
}

})
bot.login(token)

根据本网站 https://discordjs.guide/additional-info/changes-in-v12.html#permissions-haspermission-s.permissions.has() 无法正常工作,它表示 .hasPermission() / .hasPermissions() 现在已从 v11 中完全删除并添加了 permissions.has().是的,我的机器人升级到 v12 所以请帮助。

正确的使用方法是.hasPermission('MANAGE_MESSAGES')

if (!msg.member.hasPermission('MANAGE_MESSAGES'))

您正在使用使用 hasPermission() 方法的 GuildMember class。您查看的是权限 class.

https://discord.js.org/#/docs/main/stable/class/GuildMember