With Action
It will shorten your codes but it may make the codes harder to read for new coders
with
lets you assign and carry pipeline value with its type as a dot .
inside that control structure, it's like a shorthand. If the value of the pipeline is empty, dot is unaffected and when {{else}}
is used, that branch is executed instead.
Affected dot inside with
is important because methods mentioned above in this documentation:.Server.ID
, .Message.Content
etc are all already using the dot on the pipeline and if they are not carried over to the with
control structure directly, these fields do not exists and template will error out. Getting those values inside with
and also range
action would need $.User.ID
for example.
Like if
and range
actions, with
is concluded using {{end}}
and variable scope extends to that point.
with
seems easy, but it may confuse novice coders when your command is complex.
Example
To demonstrate the simple usage of
with
:
To demonstrate how
$
works insidewith
block:
The .
inside the with
block will be referred as what the (getMember 204255221017214977)
outputs. .User.Mention
here will mention YAGPDB, while $.User.Mention
will mention the user.
Harder example of
with
:
Though this command doesn't need any with
in fact, you can spot that it is quite hard to read the codes when there are too many with
functions inside a command. Putting too many with
functions inside a command will be a hell for experts and novices alike to read.
Last updated
Was this helpful?