Search docs...

Start typing to search documentation

Chat Guide

Triggers & Lua

Automation that runs around every message.

Triggers are event-driven scripts on characters. They fire at chat start or around messages, and can read history, set variables, inject system text, or stop a send.

The script format uses indent-scoped commands compatible with RisuAI trigger scripts v2, so existing cards' automation imports and runs.

Scripts with low-level access unlock effects that reach outside the chat:

runLLM checkSimilarity extractRegex runImgGen showAlert sendAIprompt triggerlua

LLM and image effects call real models and cost tokens. They require being signed in and run through your account.

For logic beyond the trigger VM, characters can carry Lua. The runtime exposes about 50 functions: chat access, variables, alerts, LLM calls and more. Compatible with RisuAI's Lua surface.

lua
onOutput = async(function(triggerId)
  local msg = getChat(triggerId, -1)
  if string.find(msg.data, "secret") then
    alertNormal(triggerId, "Secret mentioned!")
  end
end)
listenEdit("editoutput", function(triggerId, data)
  return data:gsub("%s+$", "")
end)

Lua hooks rewrite text in flight: your input before assembly, the output before saving, and the raw request before it is sent.

Hooks run in order with regex scripts of the same stage. Use the request log to see the result of the whole pipeline.

Display and request script modes run sandboxed with a restricted command set. Scripts cannot touch your account, keys, or other conversations. The worst one does is garble its own chat.