i am having an issue with a Run script. I am using Discord Bot Maker for JavaScript code with run script in it. As you can see, this is a Persistent Role system. It is supposed to keep your roles, if you leave the discord server, and give them back if you return. But once I upgraded to discord.js V12 i have gotten this error, and can't figure out how to fix it. Does anyone have an idea?
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);
})()
In version 12 <member>.addRole()
has been replaced by <member>.roles.add()
Try changing mem.addRole(elm)
to mem.roles.add(elm)