Advertisement
azcraze

Conditional Block Alts

Oct 23rd, 2021
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. {
  2. "title": "**Forget about `or`/`any` and `and`/`all` conditional blocks**",
  3. "description": "They can break easily, are lengthy and can be tedious to maintain and look at.\n\nThe method I came up with and always use now involves the use of an `in` block, that I either use as an `or` or an `and` for my conditions.\n\nTo demonstrate this method, let's check if the user of the tag has a specific role and/or if the first argument in the input has 'help' in it, as an example.\n\nThe snippet below looks longer because I added comments for you to understand what each line does, but in 'production', you can remove them to shorten it if you wish to.\n\n> 💡 Tip: A good practice in my opinion is to store your checks in variables so you give them a name and can know at a glance what you are checking for, and reuse them as many times as needed throughout the rest of your code.\n```\n{=(COMMENT):Shorter alias, in case you need to check for the user roles IDs often.}\n{=(ur):{user(roleids)}}\n{=(COMMENT):ID of the role to check.}\n{=(role):role_id}\n\n{=(COMMENT):Individual named checks.}\n{=(hasRole):{contains({role}):{ur}}}\n{=(isHelp):{in(help):{1}}}\n\n{=(COMMENT):Demonstration of an alternative to 'or' and 'and' blocks, using an 'in' block.}\n{=(COMMENT):Returns true if any of the checks returned true.}\n{=(orCheck):{in(true):{hasRole} {isHelp}}}\n{=(COMMENT):Returns true if all of the checks returned true. Make sure to put as many 'true' in the 'in' block as your number of checks. In this case: two.}\n{=(andCheck):{in(true true):{hasRole} {isHelp}}}```",
  4. "color": 3092790
  5. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement