Skip to content

Local variables

Use $set to keep a value for later in the same field. It receives a local name and an expression for its new value.

An assignment updates the nearest accessible local if one already exists; otherwise it declares a local in the current block. No type declaration is needed, and later assignments may change the value’s kind.

$set(@total, 0)
$each([1, 2, 3] as @number)
$set(@total, @total + @number)
$end
Total: @total

Result:

Total: 6

Since @total was declared before the loop, each assignment updates the same variable. Removing the indentation still produces exactly Total: 6.

Directive lines disappear, but intentional blank lines remain. Adding a blank line before Total: adds one to the output too.

A local first declared inside a branch or loop is available only in that block. Loop item and index bindings have their own scope and shadow matching outer names.

Assigning to a registered name creates a local without mutating Discord data. The initializer resolves before the declaration, allowing you to read a context value and keep a locally modified version.

Each message field starts with its own locals. A total calculated in content is not available in an embed description, and one execution leaves no locals for another.

Continue with conditions to choose text, or loops to traverse a list.