Daddify Your StreamElements Bot

Sometimes the best interactions you can have in chat are the ones you're not ever expecting. Commands are a great way for your chat to interact with the stream in a controlled, (usually) passive way, but what if you were able to trigger responses without explicitly using commands? Fortunately, StreamElements has you covered.

Firstly, StreamElements offers keywords, which are basically a selection of tag-like words that can trigger the command, without the need for an exclamation mark. For instance, if I add pizza as a keyword, I can make the bot respond with PIZZA? WHERE? Pretty neat, right?

That's cool if you have a keyword that can be used anywhere in the sentence, but if we want to get more advanced with how the sentence should be structured, then StreamElements also supports regular expressions (regex). Regex can super useful for creating very specific conditions for triggering commands.

Let's daddify the StreamElements bot. Every time someone starts a sentence with I'm, the bot should respond with 'Hi <message>, I'm dad!'

Things to note off the bat: we can't use 'I'm' as a keyword because it might be used later in the sentence, which unfortunately messes up the response variable (it captures everything after the first word). Therefore, we need to use regex to ensure the 'I'm' is at the very start of the message.

Below I'm going to walk through how to add this command to your StreamElements bot.

Firstly, you need to go to your Chat Commands, then click New Command. Click Show Advanced at the bottom.

Enter the following for these fields:

  • Command: i'm
  • Response: Hi $(1:), I'm dad.
  • Regular Expression: (?i)^\bi'?m\b.*$

Here's a brief explanation of what's happening. The response uses $(1:) to capture the message following the command (which isn't really a command in this case).

The regular expression looks confusing at first, but when broken down it's actually quite understandable!

  • (?i) - makes the regex case-insensitive, so as to match both I'm and i'm
  • ^ - the caret means 'the beginning of a line'; as we want to make sure 'I'm' is at the start of the message
  • \b - this metacharacter serves to identify 'word boundaries', which lets you look for whole words only. If we had no word boundaries, it would match 'I'mkalsjdlkasjdlkasd <message>'. Here I've wrapped 'I'm' in two \b anchors that essentially only matches 'I'm' on its own
  • .* - this is more of a twofer, the period matches ANY character and the asterisk means zero or more occurrences of the preceding character. Effectively, this is the 'wildcard' part that represents the <message> portion of the response
  • $ - not really necessary here, but put in for completeness; the dollar sign anchor means the end of the line

There you have it! Now the bot will respond with 42% more dad-ness, making for some pretty hilarious interactions.

There are some other cool things you can do with regex; for instance, it can also serve as a good tool for catching specific words and any variants (useful for moderators). I definitely recommend Regex101 - this awesome site lets you play around with different regexes and has handy tools for testing them against different messages.

Enjoyed this post? This is the first in a multi-part series of cool things you can add to your bot. If you found it useful, feel free to share 😊

Until next time!

Edit: You could modify the regex to allow a preceding word. The capture would be from the second word onwards in that case.

  • Command: i'm2
  • Response: Hi $(2:), I'm dad.
  • Regular Expression: (?i)^.+\s\bi'?m\b.*$

Leave a Reply

Your e-mail address will not be published. Required fields are marked *