【问题标题】:How to fix "TypeError: message.member.hasPermission is not a function" in Discord.js? [duplicate]如何修复 Discord.js 中的“TypeError:message.member.hasPermission 不是函数”? [复制]
【发布时间】:2021-12-15 11:46:00
【问题描述】:

我正在制作权限处理程序,但收到错误“TypeError:message.member.hasPermission 不是函数”。我的错误是什么?

        const validPermissions = [
        "CREATE_INSTANT_INVITE",
        "KICK_MEMBERS",
        "BAN_MEMBERS",
        "ADMINISTRATOR",
        "MANAGE_CHANNELS",
        "MANAGE_GUILD",
    ]

    if(command.permissions.length){
        let invalidPerms = []
        for(const perm of command.permissions){
          if(!validPermissions.includes(perm)){
            return console.log(`Invalid Permissions ${perm}`);
          }
          if(!message.member.hasPermission(perm)){
            invalidPerms.push(perm);
          }
        }
        if (invalidPerms.length){
          return message.channel.send(`Missing Permissions: \`${invalidPerms}\``);
        }

【问题讨论】:

  • 控制台在这里似乎很清楚:message.member.hasPermission is not a function。检查到底是什么message.member.hasPermission(或在此处发布)
  • 请提供足够的代码,以便其他人更好地理解或重现问题。
  • discord.js 的文档在更改日志GuildMember#hasPermission 中说:…The GuildMember#hasPermission shortcut/helper method has been removed.… 你确定hasPermission 存在于你使用的member 版本吗?跨度>
  • 谢谢!尽管如此,我很少会徒劳地查看文档

标签: javascript node.js discord discord.js


【解决方案1】:

message.member.hasPermission() 在 djs v13 中已经是removed,你现在需要使用message.member.permissions.has()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-02-18
    • 2021-01-13
    • 2020-09-03
    • 2022-01-17
    • 2020-09-23
    • 1970-01-01
    • 2021-11-02
    • 2019-10-28
    相关资源
    最近更新 更多