Control Flow
eval
$eval[]
$eval takes text, parses it as BDFD code and runs it in the current script.
Syntax
$eval[bdfdCode]
Exactly one argument; two arguments are rejected (Invalid argument count for $eval: 2.). An empty argument is accepted and produces nothing.
How It Works
- The argument is evaluated like any other argument: functions written inside it run first, and their results are put into the text.
- That resulting text is then parsed as BDFD code.
$evalis the only function that turns text back into code; a$that comes from a variable or from$replaceTextis otherwise just text. - The parsed code runs in the same invocation as the caller (same context and variables).
- When the script is producing a response (the normal case), the text produced by the evaluated code is written into the response where
$evalstands, and$evalitself returns an empty string. Text written before$evalis flushed before the evaluated code runs. - A function name that does not exist in the evaluated text is not an error: it stays as literal text.
Example
$onlyForIDs[123456789012345678;Owner only!]
$title[Code Evaluation]
$description[Result:
$eval[$message]]
$color[#5865F2]
Building the code with $replaceText (here @@ stands for the dollar sign) shows that the text is parsed only by $eval:
$eval[$replaceText[@@toUpperCase[abc];@@;$]]
This sends ABC; without $eval, the same $replaceText would send the literal text $toUpperCase[abc].
Warnings
- Security:
$evalruns any code it is given. Never pass unsanitized user input to it: the evaluated text is run as code.
Try it
Paste an example into the playground to preview its message (functions that act on Discord are not run), or build the same thing with blocks.