简体   繁体   中英

Discord.js Level Roles

 //level roles

var role = message.guild.roles.cache.find(role => role.name === "test");

if(xpfile[message.author.id].level == 1)message.member.guild.roles.add(role);

This is the code for the Level Roles from my XP System. Can someone say me why it dosen't work? There is no error, but the Bot don't add the Role.

If you want to add the role to the user you need to do something like this:

 //level roles

var role = message.guild.roles.cache.find(role => role.name === "test");

if(xpfile[message.author.id].level == 1)message.member.roles.add(role);

Removing the.guild as you do not need to access the guild of the message but only the member.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM