(node:65297) UnhandledPromiseRejectionWarning: TypeError: mem.addRole is not a function

(node:65297) UnhandledPromiseRejectionWarning: TypeError: mem.addRole is not a function

我遇到了 运行 脚本的问题。 我将 Discord Bot Maker 用于 JavaScript 代码,其中包含 运行 脚本。 如您所见,这是一个持久角色系统。 如果你离开不和谐服务器,它应该保留你的角色,如果你 return,它应该把它们还给你。 但是一旦我升级到 discord.js V12,我就遇到了这个错误,并且不知道如何修复它。 有人有想法吗?

const roles = tempVars("roles");
const arr = roles.split(',');
const guild = client.guilds.cache.get(tempVars("serv_id"));
const mem = tempVars("mem");

if (!roles) console.error('Role list is undefined, cant add roles.');

(async () => {
    for (var i = 0; i < arr.length; i++) {
        let elm = arr[i];
        if (elm !== "@everyone") {
            elm = elm.replace('<@&', '')
                .replace('>', '');
            mem.addRole(elm)
                .catch(console.error);
            await require('util')
                .promisify(setTimeout)(1000)
        }
    }
console.log(`Added all applicable roles to ${mem.user.tag}`);
Actions.callNextAction(cache);
})()

在版本 12 中 <member>.addRole() 已被 <member>.roles.add()

取代

尝试将 mem.addRole(elm) 更改为 mem.roles.add(elm)