Skip to content

Your First Automation

Let’s build a simple automation: when someone types !dice in Twitch chat, the bot rolls a random number and replies.

  • A Rawtoh account at app.rawtoh.io
  • A Twitch module connected and online
  1. Open the Script panel
  2. Click New Action
  3. Set the path to twitch/dice-roll
  4. Paste this code:
const user = event.payload.user;
const roll = Math.floor(Math.random() * 6) + 1;
await module.request("twitch", "sendMessage", {
text: `@${user} rolled a ${roll}! 🎲`
});
log("Dice roll:", user, "got", roll);
  1. Save
  1. Click New Trigger on your action
  2. Set:
    • Module group: twitch
    • Event name: ChatMessage
    • Cooldown: 2000 (2 seconds, to prevent spam)
  3. Write the condition:
event.payload.message.toLowerCase().startsWith("!dice")
  1. Save

Go to your Twitch chat and type !dice. You should see:

  1. An event appear in the Events panel
  2. A process showing the trigger matched and the action ran
  3. The bot reply in chat with a random number
  1. The Twitch module detects the !dice message and emits a ChatMessage event
  2. Rawtoh receives the event and checks all triggers for ChatMessage on the twitch group
  3. Your trigger condition evaluates — "!dice".startsWith("!dice") returns true
  4. The action runs: generates a random number and calls module.request to send a reply
  5. The Twitch module receives the command and posts the message in chat

All of this happens in a few milliseconds.

  • Add more commands by creating new actions and triggers
  • Use storage to remember data between executions
  • Explore Writing Actions for more advanced patterns