How to Create a Twitch Command Script for Streamlabs Chatbot — Part 3: Implementing the Logic

Nintendo Engineer
The Startup
Published in
4 min readJan 7, 2021

--

Photo by Florian Olivo on Unsplash

In Part 2 we set up our basic structure and now we are ready to get to the juicy bit, where the script will come to life, so what are we waiting for?

Implementing the Logic

Our command logic goes in the Execute(data) method, which gets called by SC when a message is posted in the chat. There are some gotcha’s to consider but I’ll guide you through them.

Remember how I said that any command (or message, for that matter) in the chat will trigger our Execute(data) method?

As we only want to respond to the command !mulder, we should verify that the first thing in the message actually says that. We use the data parameter that is passed for this, as it contains some properties and methods we can leverage.

One such method is the data.GetParam(int id). We’ll use it to get the first thing in the message and verify if it equals !mulder. If it doesn’t, we don’t do anything. But enough talk, let’s implement it:

Our command should state whether someone is extraterrestrial or not, based on probability. Let’s introduce that probability and give it a value of about 10%, so every one out of ten people is actually an alien. Well, damn.

--

--

Nintendo Engineer
The Startup

Geotechnical Engineer by education, .NET Developer by trade, Nintendo fan by design. Find me on Discord: NintendoEngineer#3083