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.
Execution flow
Section titled “Execution flow”- A chat command, channel-point reward, or event triggers the template.
- Viewer placeholders are substituted:
&p1receives the first word after the command,&p2the second, and&tcaptures everything after the highest numbered word. See AST Syntax & Data. - The bot assembles the runtime context—channel, user, streamer plan, and any event payload.
- The template text is tokenized.
- Those tokens are parsed into an executable AST.
- The AST evaluates top to bottom, running functions from left to right.
- Any variable writes are saved to memory, cache, or the database as they execute.
- The finished message posts to chat, and any command references (
#(...)) run afterward in order, each sending its own reply.
Who the command runs as
Section titled “Who the command runs as”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.
Common error messages
Section titled “Common error messages”| Message | What it means | What to do |
|---|---|---|
[Unknown function: name] | No AST function matches that name | Double-check the spelling in AST Functions Reference. Aliases like vip and add.vip are both valid |
Usage: $(name ...) or $(name ...) usage text | A required argument is missing or invalid | Match your arguments against the syntax in the functions reference |
Error: permission denied - 'name' requires moderator permissions | An AI chat request tried to call a function above the caller’s role | Nothing is broken—the viewer simply lacks the required role |
[Parse error: …] followed by part of your text | The 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 malformed | Compare your loop against AST Syntax & Data |
[Loop error: invalid range loop syntax] | A range loop is missing one of its clauses | Provide all three parts: start, condition, and step |
[Loop error: missing loop body] or [Loop error: unclosed loop body] | The { ... } block is missing or unclosed | Add the missing curly braces |
delay: must be between 0 and 60 seconds | $(delay) received a duration outside 0–60 | Pick a value from 0 to 60; for longer waits, switch to $(timer ...) |
timer: usage: … | $(timer) is missing its seconds or body | Include both parts: $(timer seconds "body") |
timer: could not schedule timer | Saving the timer failed, such as hitting a pending-timer cap or a cache error | Wait for existing timers to finish, then try again |
Limits by plan
Section titled “Limits by plan”| Limit | Free | Premium | Pro |
|---|---|---|---|
| Loop nesting depth | 2 | 3 | 4 |
| Loop iterations | 25 | 50 | 100 |
Saving to database variables (%(*name ...), %(**name ...)) | Not saved | Yes | Yes |
| Temporary VIP and moderator days in AST functions | Days ignored; role remains | Yes | Yes |
| Roulette functions | Yes | Yes | Yes |
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.
Command reference limits
Section titled “Command reference limits”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 and timer limits
Section titled “Delay and timer limits”$(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.
Debugging checklist
Section titled “Debugging checklist”1. Start simple
Section titled “1. Start simple”Verify a minimal reply works before layering on logic:
Hello $(user)!2. Add one feature at a time
Section titled “2. Add one feature at a time”Build up in stages:
- plain text
- arguments
- functions
- variables
- conditions
- loops
3. Check that a value exists
Section titled “3. Check that a value exists”When a cache or database variable might not be set yet, guard it with ^():
*(^(#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:
%(#wins 1)To increment, read the current value and store the updated sum:
%(#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.
Common gotchas
Section titled “Common gotchas”Expired cache values come back blank
Section titled “Expired cache values come back blank”Every # or ## variable expires 24 hours after its last write and reads as blank afterward. Switch to * or ** whenever a value must persist.
&t must come last
Section titled “&t must come last”Because &t consumes the remainder of the message, introducing a new numbered argument like &p3 after it triggers a parser error.
&p1 is one word
Section titled “&p1 is one word”&p1 only grabs the first word. Whenever you expect multi-word input—like a full phrase or a title with spaces—use &t.
Timer bodies run later
Section titled “Timer bodies run later”$(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.
Command references are sent separately
Section titled “Command references are sent separately”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.
Loops are often unnecessary
Section titled “Loops are often unnecessary”Whenever a single expression or a command reference can do the job without a loop, go with the simpler approach.
Action functions in public commands
Section titled “Action functions in public commands”Always align a command’s access level with the power of its functions. Keep sensitive actions like moderation locked down to trusted moderators.
Practical debugging order
Section titled “Practical debugging order”When something goes wrong, check these five questions in order:
- Are the chat arguments landing where I expect?
- Did I initialize the variable before reading it?
- Am I overwriting the value when I meant to add to it?
- Is the function allowed in this context, on this plan, and for this event?
- Did I hit a loop or command-reference depth/count limit?
Safe testing tip
Section titled “Safe testing tip”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.