If user [condition] then [output] else [output]

Asked Nov 29, 2022·4 replies·Last activity 3 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

I want a command that gives output1 if User1 uses it and if any other user uses it output2 should come

sry for my english rn xd

4 replies

$(eval "$(user)"=="User_Allowed_To_Use"?"Message_For_User":"Message_For_Others")

Expanding on this, what if it were a list of users (let's say 2) ?

Would that be

$(eval "$(user)"=="User_Allowed_To_Use"||"User2_Allowed_To_Use"?"Message_For_User":"Message_For_Others")

?

Hey @Swanky Panda!

No, such test will always produce a truthy output, so you'll always have Message_For_User as output, and never Message_For_Others.

For the code to work as expected you have two solutions:

  • the basic one, which quickly gets cumbersome:
$(eval '$(user)' === 'User_Allowed_To_Use' || '$(user)' === 'User2_Allowed_To_Use' ? 'Message_For_User' : 'Message_For_Others';)
  • the better one, because it's just cleaner code with no repetition:
$(eval ['User_Allowed_To_Use', 'User2_Allowed_To_Use'].includes('$(user)') ? 'Message_For_User' : 'Message_For_Others';)

AH ok 🙂

Thanks very much :) (Not used JS much) !!

Zoe