[英]Loop through roles and give the user a corresponding role to the one it currently has
I need to make it so the bot searches through the priority list of corresponding roles, finds one that matches the one the user currently has and gives out a corresponding one based on the list.我需要这样做,以便机器人搜索相应角色的优先级列表,找到与用户当前拥有的角色匹配的角色,并根据列表给出相应的角色。 After that, it stops searching and moves on.之后,它停止搜索并继续前进。 If the user does not have the first role, it just skips to the next one and keeps comparing untill it finds a match.如果用户没有第一个角色,它只会跳到下一个角色并继续比较,直到找到匹配项。
This is what I have right now.这就是我现在所拥有的。 It seems to loop through the list, but stops when it hits the else, since I wasn't able to make it go back to searching.它似乎遍历列表,但在遇到 else 时停止,因为我无法让它返回到搜索状态。
if(
newMember.roles.cache.has(yellow) &&
newMember.roles.cache.has(role2) == false
) {
newMember.roles.remove(yellow)
var server_roles = {role2:yellow, role1:blue};
for (var prop in server_roles) {
if (
newMember.roles.cache.has(prop)
) {
console.log("User has role: " + prop)
newMember.roles.add(server_roles[prop])
break
}else(
console.log("User does not have: " + prop)
// Continue searching through the list
)
}
I think you have to use CONTINUE instead of BREAK.我认为您必须使用 CONTINUE 而不是 BREAK。
reference from参考自
https://www.w3schools.com/js/js_break.asp https://www.w3schools.com/js/js_break.asp
"The break statement "jumps out" of a loop." “break 语句“跳出”一个循环。”
"The continue statement "jumps over" one iteration in the loop." “ continue 语句“跳过”循环中的一次迭代。”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.