TypeError: role.setPermissions is not a function even though TypeScript says it is

TypeError: role.setPermissions is not a function even though TypeScript says it is

我正在创建一个循环遍历服务器中所有角色的命令,removes/adds 一个选定的权限(如果可以的话)。将鼠标悬停在它上面会显示函数的描述。

async execute(client, msg, args, cooldowns, guildForPre, prefix) {
    if(msg.member.permissions.has("MANAGE_ROLES")) {
        let roles = (await msg.guild.roles.fetch()).cache;
        let highPos = getRoleByMention(args[1], msg.guild)?.position || msg.guild.roles.highest.position
        let lowPos = getRoleByMention(args[2], msg.guild)?.position || msg.guild.roles.everyone.position
        roles = roles.filter(r => r.permissions.has(args[0]))
        roles = roles.filter(r => r.position <= highPos && r.position >= lowPos)
        let replaced = ''
        for await (const [, role] of roles) {
            if(role.position >= msg.guild.me.roles.highest.position || role.position >= msg.member.roles.highest.position) continue;
            await role.setPermissions(role.permissions.remove(args[0]))
            (replaced.length) ? replaced += `, ${role.name}` : replaced += `${role.name}`
        }
        msg.channel.send("Replaced roles: " + replaced)
    }
}

getRoleByMention函数:

function getRoleByMention(mention, guild) {
    const id = mention.slice(3, mention.length-1)
    return guild.roles.cache.get(id)
}

我的命令处理程序参数输入正确,输入的命令如下:

m.removeRolePerm MANAGE_MESSAGES @Dyno @Dyno

是因为他们是同一个角色吗? docs 表示这是一个有效的函数。我正在使用 v12.

问题实际上是后面的语句。这是因为缺少分号。添加分号应该可以正常工作。将其更改为此将消除错误并使其也能正常工作

await role.setPermissions(role.permissions.remove(args[0]))
           if (replaced.length) replaced += `, ${role.name}`
           else replaced += `${role.name}`