#Role check

1 messages · Page 1 of 1 (latest)

tribal turtle
#

interaction.member.cache.some(…) checks that if the member has the role or not

nocturne drift
#

Ok

tribal turtle
#

If he has the role, it will return true

nocturne drift
#

How can I have it do a specific reply if its false?

tribal turtle
#

! is the logical not operator

#

So !true is false and !false is true

nocturne drift
#

So operator is the interaction.member portion?

hoary atlas
tribal turtle
#

So adding a not will convert the condition into checking if member doesn’t have the role

nocturne drift
tribal turtle
nocturne drift
#

Ohhhhhhhh ok

#

So I know lua pretty well, I can just throw an else at it

#

In javascript how can I do an "else"

hoary atlas
#

else?

nocturne drift
#

So it can read like

if user.has.role then
do whatever
else
do other thing

tribal turtle
#

Yes that will work

nocturne drift
#

So I can do else in javascript?

tribal turtle
#

Yes

#

if (condition) {
Do something
} else {
Do something else
}

hoary atlas
tribal turtle
#

Else if isn’t anything new btw

narrow flax
#
if (!message.member.roles.cache.some(role => role.name === 'Something')) 
nocturne drift
#

Lmfao

#

I tried to literally do an else

#

FML

hoary atlas
tribal turtle
tribal turtle
#

if () {} else { if () {} }

#

This is what else if basically is

nocturne drift
#

Thats confusing af

hoary atlas
#

nah its nested

nocturne drift
#

Sorry learning javascript slowly xD

#

I know nested is doing ({})

tribal turtle
#

You can take it slow, I’m not the best at teaching lol

narrow flax
#
if (message.member.roles.cache.some(role => role.name === 'Something'))  {
console.log("tthis guy have the role")
} else {
console.log("this guy don't have the role")
}
maiden field
hoary atlas
maiden field
#

if()doing only one thing;

tribal turtle
#

Yeah else is optional

maiden field
#

You don't need {} if you put only one thing

tribal turtle
#

Yeah that too a single statement doesn’t need a block

nocturne drift
#
  execute(interaction, member) {
    if (
      !interaction.member.roles.cache.some((role) => role.name === "Subscriber")
    ) {
      interaction.reply({ content: "Download Sent", ephemeral: true });
      interaction.member.send({
        content: "Here is your download",
        files: ["NW_minion_x64.exe"],
      });
    } else {
      interaction.reply({
        content: "You need to purchase before downloading",
        ephemeral: true,
      });
    }
  },
};```
#

So like this??

#

Lets try and see 😉

tribal turtle
#

Should work perfectly

nocturne drift
#

OOF no good

#

I have role and still sent

tribal turtle
#

Remove the !

nocturne drift
#

It gave me the esle

#

Oh

hoary atlas
nocturne drift
#

Beautiful

#

Removing the ! worked

#

So ! means to strictly check

#

Or well

#

! if ur not using an else

tribal turtle
#

Yup earlier you were using it to check if member doesn’t have the role, now you are using it to check if he has the role.
So the not is not needed

nocturne drift
#

Ohhhhhhhhhhhhhh

#
  execute(interaction, member) {
    if (
      interaction.member.roles.cache.some((role) => role.name === "NWB Subscriber" || interaction.member.roles.cache.some((role) => role.name === "NWB Premium Subscriber")
    )) {
      interaction.reply({ content: "Download Sent", ephemeral: true });
      interaction.member.send({
        content: "Here is your download",
        files: ["NW_minion_x64.exe"],
      });
    } else {
      interaction.reply({
        content: "You need to purchase before downloading",
        ephemeral: true,
      });
    }
  },
};```
#

I learned how to do "or" and "and" aswell. Figured those would be massively useful like this 😉

#

I apprecaite the help @tribal turtle !!!!!

#

And the rest of yall

tribal turtle
#

Btw there is one thing that will optimise your code.
.some iterates through the whole array, so since you are using it twice if go through the array twice. Better will be put that inside the callback:
role => role.name === 'name1' || role.name === 'name2'
Then a better to write the same thing is:
role => ['name1', 'name2'].includes(role.name)

nocturne drift
#

😉

#

Wait what @tribal turtle Can u write that portion n show me what u mean?

#
      interaction.member.roles.cache.some((role => ['NWB Subscriber', 'NWB Premium Subscriber'].includes(role.name))```
#

Like this?

tribal turtle
#

Yes

nocturne drift
#

That worked beautifully

tribal turtle
#
      interaction.member.roles.cache.some(role => ['NWB Subscriber', 'NWB Premium Subscriber'].includes(role.name))```
#

You had a extra bracket

#

Before role

nocturne drift
#

Its fine, I made it work 🙂

#

Thanks for teaching me a trick 😉