Skip to content

AST Execution, Errors & Limits

Follow how an AST command executes step by step, decode common error messages, and check plan limits for loops, command references, timers, and saved variables.

Come back to this page whenever a command throws an error, stays silent, or runs in a surprising order. It walks through every stage of command execution and lays out the hard limits for each plan.

  1. A chat command, channel-point reward, or event triggers the template.
  2. Viewer placeholders are substituted: &p1 receives the first word after the command, &p2 the second, and &t captures everything after the highest numbered word. See AST Syntax & Data.
  3. The bot assembles the runtime context—channel, user, streamer plan, and any event payload.
  4. The template text is tokenized.
  5. Those tokens are parsed into an executable AST.
  6. The AST evaluates top to bottom, running functions from left to right.
  7. Any variable writes are saved to memory, cache, or the database as they execute.
  8. The finished message posts to chat, and any command references (#(...)) run afterward in order, each sending its own reply.

Every run carries a context with the channel, user, streamer plan, and—for event-driven messages—the event payload. Event functions such as $(cheer.amount) pull directly from that context.

How permissions are enforced depends on what triggered the run:

  • Your custom commands, rewards, and events follow the access level you configured on them. The bot does not recheck function role metadata, though individual functions may still enforce context rules. Always set command access to match what the command is allowed to do.
  • AI chat requests enforce every function’s minimum access level. If a regular viewer asks the AI to ban someone, the bot returns a permission error unless that viewer is a moderator. The AI also respects the access setting of any custom command it invokes.
  • Command references (#(...)) called from your own commands bypass the target command’s access check—only the outer command’s access level is evaluated. If a public command calls a mod-only command, that mod-only command will still run. Always consider the full call chain when setting access.
MessageWhat it meansWhat to do
[Unknown function: name]No AST function matches that nameDouble-check the spelling in AST Functions Reference. Aliases like vip and add.vip are both valid
Usage: $(name ...) or $(name ...) usage textA required argument is missing or invalidMatch your arguments against the syntax in the functions reference
Error: permission denied - 'name' requires moderator permissionsAn AI chat request tried to call a function above the caller’s roleNothing is broken—the viewer simply lacks the required role
[Parse error: …] followed by part of your textThe parser couldn’t read that chunk—often a missing ) or "Check for an unclosed $(, %(, *(, or quotation mark near the snippet shown
[Loop error: invalid loop syntax]The loop’s for header is malformedCompare your loop against AST Syntax & Data
[Loop error: invalid range loop syntax]A range loop is missing one of its clausesProvide all three parts: start, condition, and step
[Loop error: missing loop body] or [Loop error: unclosed loop body]The { ... } block is missing or unclosedAdd the missing curly braces
delay: must be between 0 and 60 seconds$(delay) received a duration outside 0–60Pick a value from 0 to 60; for longer waits, switch to $(timer ...)
timer: usage: …$(timer) is missing its seconds or bodyInclude both parts: $(timer seconds "body")
timer: could not schedule timerSaving the timer failed, such as hitting a pending-timer cap or a cache errorWait for existing timers to finish, then try again
LimitFreePremiumPro
Loop nesting depth234
Loop iterations2550100
Saving to database variables (%(*name ...), %(**name ...))Not savedYesYes
Temporary VIP and moderator days in AST functionsDays ignored; role remainsYesYes
Roulette functionsYesYesYes

On Free, database variable writes are silently skipped with no error—the command finishes normally, but the value isn’t stored. Reading existing database values still works.

Free permits up to two nested loop levels (a loop inside a loop), Premium permits three, and Pro permits four.

Calling #(commandName args) triggers another custom command once the outer reply finishes:

  • References can nest up to five levels deep.
  • Any command already active in the current call chain is blocked so a command cannot trigger itself in a cycle.
  • A single run can execute at most 50 references total across every nesting level.
  • Each referenced command sends its own separate message after the main reply.
  • $(delay N) halts execution for up to 60 seconds, holding back the rest of the command until the pause ends.
  • $(timer seconds body) schedules its body to run later—anywhere from 1 to 604800 seconds (seven days)—and returns immediately.
  • Timers store their body and context in the bot’s cache, letting them survive restarts.
  • If the bot is offline when a timer comes due, it can still run if it is under 10 minutes late; once it hits that threshold, it expires.
  • Every timer runs at most once. A crash after a timer is claimed can drop the action, so execution is not guaranteed.
  • Timers can nest up to five levels deep.
  • Each channel may have up to 100 pending timers at once, alongside a shared cap of 10,000 pending timers and a 64 KiB size cap per saved job.

Verify a minimal reply works before layering on logic:

Terminal window
Hello $(user)!

Build up in stages:

  1. plain text
  2. arguments
  3. functions
  4. variables
  5. conditions
  6. loops

When a cache or database variable might not be set yet, guard it with ^():

Terminal window
*(^(#wins) ? %(#wins) : "no wins yet")

4. Remember that assignment replaces the value

Section titled “4. Remember that assignment replaces the value”

This does not increment—it overwrites #wins with 1 on every run:

Terminal window
%(#wins 1)

To increment, read the current value and store the updated sum:

Terminal window
%(#wins *(%(#wins) + 1))

5. Check the event that starts the command

Section titled “5. Check the event that starts the command”

Event functions like $(cheer.amount) and $(reward.input) rely on event data in the context. Testing them from normal chat returns blank, unknown, or 0, which is completely normal.

Every # or ## variable expires 24 hours after its last write and reads as blank afterward. Switch to * or ** whenever a value must persist.

Because &t consumes the remainder of the message, introducing a new numbered argument like &p3 after it triggers a parser error.

&p1 only grabs the first word. Whenever you expect multi-word input—like a full phrase or a title with spaces—use &t.

$(timer ...) stores its body for later execution rather than running it inline. The outer command finishes immediately, and the scheduled message and actions fire when the timer comes due—unless it reaches 10 minutes late, in which case it expires without running.

The main message always sends first. Sibling #(...) references then run in order and post their own replies, with each command’s nested references finishing before the next sibling starts. If the main message fails to post, referenced commands are skipped. Output from a referenced command is never re-parsed as AST.

Whenever a single expression or a command reference can do the job without a loop, go with the simpler approach.

Always align a command’s access level with the power of its functions. Keep sensitive actions like moderation locked down to trusted moderators.

When something goes wrong, check these five questions in order:

  1. Are the chat arguments landing where I expect?
  2. Did I initialize the variable before reading it?
  3. Am I overwriting the value when I meant to add to it?
  4. Is the function allowed in this context, on this plan, and for this event?
  5. Did I hit a loop or command-reference depth/count limit?

Confirm your reply text and branching first, then drop in side effects.

For instance, test your output and conditions before adding actions like:

  • $(ban ...)
  • $(vip ...)
  • $(set.title ...)
  • $(start.poll ...)
  • $(trigger.send ...)

That way you know the logic behaves cleanly before it touches anything live on your channel.

Docs assistant

Ask in your own words. Answers come from these docs, with links to the right page.

Try asking

Current page: AST Execution, Errors & Limits

AI can make mistakes. Check the linked page.