#Select Menu Loops for Role Giving

1 messages · Page 1 of 1 (latest)

dense mirage
#

I mean "members.roles.remove" for each if-else ifs.

long sparrow
#

That sentence now includes: for, forEach, if, else, else if. It didn’t make anything clearer by that

dense mirage
#

Okay lemme summary it. I'm trying to check if the user has the roles in the array; it will remove it from the user. If they dont, it will just end the checking.

long sparrow
#

Okay, so filter the array and at the end of the function check if length > 0 and remove in that case only

dense mirage
long sparrow
dense mirage
#

It does not contain any loops, but it would be better than checking bunch of roles with .has() method.

long sparrow
#

You can do the .has check in the .filter, so one line only

dense mirage
#

But won't that be only for the item itself?

long sparrow
#

The filter gets called for every item in the array

dense mirage
#

Hmm...

long sparrow
#

So (pseudocode): array.filter(role=> user shouldn’t have it && user does have it) and pass that to the remove call

#

If its length >0

dense mirage
#

Alright. I'm going to test it out now.

#

@long sparrow, I have a small question. Is the filtering global or inside code block (curly brackets)?