[EN] Channel points are a (relative) new feature on Twitch. Viewer can collect it while watching. With this simple trick, your Bot can react on rewards with tmi.js. For exmaple let the bot greet this user!
HINT: Your redeem has to have an input field for text inputs, otherwise there is not text push to IRC and it is invisible for the bot!
Channel points allows the viewer of a Twitch streamer to collect „loyalty“ points while watching the stream, put something in chat or cheer with some Bits (Twitch digital currency). As a streamer you can offer some rewards for an amount of points. For example „Highlight my message“ for 100 channel points.
This type of rewards are nice, but also very simple and not so much interaction with the user. The streamers creativity is bounded. Twitch offers some ideas:
- Let a viewer choose which game or map you play next
- Let a viewer customize game character
- Give a friend request
- Dance on stream
But what is about rewards, that interacts with your Twitch Bot (written in Java-Script with the library tmi.js)? You could talk with all APIs (application interfaces) or do any logic you want.
How to: Twitch Bot rewards
You could write your own rewards with logic. For exmaple with Java-Script on NodeJS with the help of the library tmi.js. There is a tutorial for this at end of the tmi.js page.
Bot, tell me a joke!
For example a reward could be: „Tell me a joke!“ or „Actual weather“ with an API.
- Two bytes meet. The first byte asks, “Are you ill?”
The second byte replies, “No, just feeling a bit off.”
- How many programmers does it take to change a light bulb?
None – It’s a hardware problem
- Debugging: Removing the needles from the haystack.
Sorry for the bad computer science jokes…
This is how the reward looks like:
And this the result from the bot:
„tmi.js can’t do this!“
Correct. Eh.. no not at all. For the actual tmi.js version 1.5.0 there doesn’t exist any event listener for rewards. So tmi.js can’t do it natively like „Follow“ or „Subscription“ events. But you can listen to the
context at the message event listener. Fortunately redeemed channel points are also Twitch chat messages (when a message is required!). So we could read and detect channel rewards and differentiate them from normal messages. For my reward it is:
The secret lies in
context from a message, because redeemed rewards also generates a message in chat. From the context you can find the custom-reward-id (for my reward:
4e7f4966-3979-4bf6-af76-447fdc0717cb) key for the reward. With an if clause you have to search for this every message. Then you can react on this!
Write own Rewards with tmi.js
Let’s develop an easy reward „Tell me a joke!“. First of all you’ve to create a reward on Twitch for your channel. Give them a name and number of channel points.
At your tmi.js script you have now to add an array with jokes. For example we can use my jokes from this article:
Now we have to react on the reward you create before. Then we have to find our Reward-ID like I described in the article before. For this you can redeem the reward and listen on the created message. Now you can add the logic to your tmi.js script:
The full script looks like this:
Some Reward ideas (with logic)
On my german Twitch channel BYTEthinks my viewer can collect BYTEcoins and change it with this (tmi.js-)rewards:
- Change lamp color in stream
Change overlay lamp color written in HTML & CSS in given color hexcode (e.g. #ff0000 -> red)
- Ask the bot a question!
Redirect the written question via API to WolframAlpha and return the answer (e.g. „How tall is Eiffel Tower?“ Bot: „324 meters“)
- Spotify song request
Add via Spotify API songs to the current playback queue from Spotify.
Beside that, there are an infinite number of ideas you could do as reward. Be creative! Here are some ideas for your inspiration:
- I tell you some random secret of mine
Return a random fact of an array
- Tell me a joke!
The same as above, but with an array of jokes
- Make me an VIP for 24h!
Bot react with „VIP“ command from the tmi.js library
What ideas do you have for an programmable reward system? Write a comment below! Thanks!