Skip to content

AST Recipes & Patterns

Copy-ready AST templates for counters, conditionals, viewer lookups, timed actions, polls, and predictions, along with the plan rules and limits each one relies on.

Treat these recipes as ready-to-adapt starting points—each snippet is a full custom command reply (or a pair of commands where noted). Before opening any channel-changing recipe to chat, test it in a command restricted to yourself. For syntax rules see AST Syntax & Data, and for individual functions see AST Functions Reference.

Terminal window
*( ^(#wins) ? %(#wins *(%(#wins) + 1)) : %(#wins 1) )
$(user) has %(#wins) wins!

The first line initializes #wins to 1 if it doesn’t exist yet and increments it by 1 on every run after that; the second line posts the updated total.

  • Cache variables (#) expire 24 hours after their last write. If a full day passes without anyone running the command, the count resets.
  • When the count needs to last permanently, switch to a database variable: %(*wins ...) for a channel-wide counter, or %(**wins ...) for a per-viewer counter. Database writes need Premium or Pro. On Free, writes are skipped silently without an error. See Execution, Errors & Limits.
Terminal window
%(##rank(&p1))

Because &p1 captures the first word after the command, !rank ronchi reads the value stored for the login ronchi. Omit the selector and ## or ** variables automatically target whoever ran the command.

Terminal window
*( %(#ready) == 1 ? "Ready" : "Not ready" )

A ternary *( condition ? yes : no ) only evaluates the matching branch, so keep any channel-changing action strictly inside the branch where it belongs.

Run an action only when a condition is true

Section titled “Run an action only when a condition is true”
Terminal window
*( %(#ready) == 1 ? "Ready" : "" )

Leaving the false branch as an empty string ensures nothing prints when the condition isn’t met.

This temporarily turns !spoilers off for five minutes and then restores whatever state it had before:

Terminal window
$(disable.command spoilers 300)
!spoilers is paused for five minutes.

Durations are given in seconds from 1 to 604800, and the command restores to its prior state even if the bot restarts in the meantime. See Availability functions.

The timer finishes immediately in the outer command while scheduling its message and action for five minutes later—and it can survive a bot restart:

Terminal window
$(timer 300 "Five minutes are up!" $(trigger.send airhorn))

Every timer executes at most once and expires if it reaches 10 minutes late; execution is not guaranteed if a failure happens after the timer is claimed. See Execution, Errors & Limits.

Split prediction resolution across two commands so a moderator can review the numbered outcomes before picking a winner. Set both commands to Moderators access.

Command 1, !predictions: displays the question along with its numbered choices.

Terminal window
$(get.prediction)

Command 2, !winner: resolves the prediction using either the outcome’s title or its number.

Terminal window
$(end.prediction &t)

A moderator can then run !winner Yes or !winner 1. Using &t preserves multi-word outcome titles. Every time it runs, end.prediction fetches the current Twitch prediction and refuses both non-existent numbers and titles that match more than one choice.

Run this command once—or create a roulette with ID polls on the Roulette page—and add the wheel to an OBS overlay:

Terminal window
$(roulette.create polls "Poll tie-breaker")

Next, paste this script into your Poll ended event message:

Terminal window
*($(poll.tied) ? "${$(roulette.fill polls $(poll.tied))}${$(roulette.start polls)}Tie! The wheel decides." : "${$(poll.result)} won the poll!")

When the poll ties, the tied choices replace the roulette items and the wheel spins; otherwise, chat gets the winner right away. Inside double quotes, ${ } evaluates each function, and since roulette.fill and roulette.start produce no output, only the chat sentence is sent.

This version also announces the wheel’s winner eight seconds later. Set the timer longer than the spin duration (four seconds by default), and leave the timer text unquoted so roulette.result evaluates when the timer fires rather than immediately:

Terminal window
*($(poll.tied) ? "${$(roulette.fill polls $(poll.tied))}${$(roulette.start polls)}${$(timer 8 The wheel picked $(roulette.result polls)!)}Tie! The wheel decides." : "${$(poll.result)} won the poll!")

When a poll ends with zero votes, every option counts as tied. Check poll.total first to handle that case cleanly:

Terminal window
*($(poll.total) == 0 ? "Nobody voted." : *($(poll.tied) ? "${$(roulette.fill polls $(poll.tied))}${$(roulette.start polls)}Tie! The wheel decides." : "${$(poll.result)} won the poll!"))

Restrict this command to moderators. Every vote becomes one slice on the wheel, and options with zero votes are skipped:

Terminal window
$(roulette.clear polls)*(for #o in $(poll.options) { %(ids[] $(roulette.add polls #o 1 $(poll.votes #o))) })$(roulette.start polls)Every vote is a slice. Spinning!

Use this command to announce the current leader while a poll is live. Because poll.result is blank during a tie, check poll.tied first:

Terminal window
*($(poll.tied) ? "It is a tie so far." : "${$(poll.result)} leads with ${$(poll.votes $(poll.result))} of ${$(poll.total)} votes.")

If a command grows hard to maintain, break pieces into separate commands and chain them with #(commandName args...):

Terminal window
Welcome $(user)!
#(rules)

In this setup, !welcome posts its greeting first, and then !rules runs and posts its own reply. Whenever an argument includes punctuation such as ;, ?, or /, wrap it in quotes—for example #(poll "Best map?;Nuke/Mirage")—so those characters aren’t altered along the way.

Keep these rules in mind:

  • Chains can nest up to five levels deep, with a cap of 50 total calls per run.
  • A command cannot call itself, either directly or indirectly through another command.
  • Called commands don’t check their own access setting when triggered from one of your commands—only the calling command’s access is checked, so set the outer command’s access carefully.
  • Every called command sends its own separate reply after the outer reply.

See Execution, Errors & Limits for the full rules.

PatternSyntaxPurpose
Count or start a count*(^(#x) ? %(#x *(%(#x) + 1)) : %(#x 1))Initialize a missing counter or add 1
Viewer lookup%(##rank(&p1))Read a cached value saved for a specific viewer
Persistent viewer value%(**rank(&p1))Read a viewer’s database value (requires Premium or Pro to save)
Condition*(condition ? YES : NO)Pick one of two outputs
Conditional action*(condition ? ACTION : "")Run an action only when a condition is true
Timed action$(timer seconds "message" $(action))Schedule a message and action to run later, at most once
Poll resultspoll.result, poll.tiedCheck live/final poll winners or break ties with a wheel
Call another command#(commandName args...)Trigger a follow-up command after the main reply

Docs assistant

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

Try asking

Current page: AST Recipes & Patterns

AI can make mistakes. Check the linked page.