简体   繁体   English

Discord.js 级别角色

[英]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.这是我的 XP 系统中关卡角色的代码。 Can someone say me why it dosen't work?有人可以告诉我为什么它不起作用吗? There is no error, but the Bot don't add the Role.没有错误,但是 Bot 没有添加角色。

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.删除 .guild 因为您不需要访问消息的公会,而只需要访问成员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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