【发布时间】:2021-05-16 14:22:27
【问题描述】:
我正在为客户开发一个机器人,我正在制作一个可以由(prefix) warn <user mention> 触发的警告系统。我有下面的代码。
我可以运行一次命令,它会添加警告 1 角色,但后续命令不会添加警告 2 或 3。
if (mentionedUser.roles.cache.has(warn1)){
if (mentionedUser.roles.cache.has(warn2)){
message.channel.send('Already has 2 warnings.');
mentionedUser.addRole(warn3);
}
else{
message.channel.send('Already has 1 warning.')
mentionedUser.addRole(warn2);
}
}
else{
mentionedUser.roles.add(warn1);
message.channel.send('Warned the user.');
}
【问题讨论】:
-
看起来“提到的User.roles.cache.has(warn1)”总是假的。你确定这是好的验证?我不知道不和谐,但为什么这个角色会在缓存中?
-
您可以查看这些示例:stackoverflow.com/questions/45317305/… 如果有帮助
-
@Leyffda discord.js v12 使用缓存。在 v11 中应该是
mentionedUser.roles.has(warn1)
标签: javascript node.js discord discord.js