Writing Triggers
Trigger conditions are JavaScript expressions that determine whether an action should run.
How it works
Section titled “How it works”When an event matches a trigger’s module group and event name, the condition program is evaluated. If it returns a truthy value, the linked action runs.
Available globals
Section titled “Available globals”Inside a trigger condition, you have access to:
| Global | Description |
|---|---|
event | The full event object |
trigger | The trigger itself |
log(...) | Log values for debugging |
The event object
Section titled “The event object”// event structure{ id: "evt_abc123", name: "ChatMessage", payload: { user: "viewer42", message: "!hello" }, emitter_group: "twitch", emitted_at: "2025-01-15T10:30:00Z"}Common patterns
Section titled “Common patterns”Always trigger
Section titled “Always trigger”trueMatch a command prefix
Section titled “Match a command prefix”event.payload.message.startsWith("!hello")Case-insensitive matching
Section titled “Case-insensitive matching”event.payload.message.toLowerCase().startsWith("!hello")Match a specific user
Section titled “Match a specific user”event.payload.user === "viewer42"Exclude a user
Section titled “Exclude a user”event.payload.user !== "nightbot"Combine conditions
Section titled “Combine conditions”event.payload.message.startsWith("!vip") && event.payload.user === "moderator1"Match with regex
Section titled “Match with regex”/^!(hello|hi|hey)/i.test(event.payload.message)Check payload values
Section titled “Check payload values”event.payload.amount > 100Debug with log
Section titled “Debug with log”If your trigger isn’t matching, use log() to inspect the event:
log("Event payload:", event.payload);event.payload.message.startsWith("!hello")The last expression is the return value. Logs will appear in the process details even if the condition returns false.
- Keep conditions simple — complex logic belongs in the action, not the trigger
- Use cooldowns to prevent triggers from firing too rapidly
- Test with log() to see exactly what data the event contains
- Trigger conditions have a 5-second timeout — they should be near-instant