Let’s talk about how to make a weighted random response in StreamElements. This topic was brought to us by someone in my YouTube comments. I love it!
One of my favorite things about building tutorials is all the fun requests I get on related videos. I have more ideas than I can ever produce content for because they just keep coming in. Thank you all!
My favorite way for people to ask me a question is in a comment on YouTube. Engagement is so important over there and questions help! That said, I often move the answer over to my discord for a better presentation of a solution. Now that I have this blog set up, I’ll be doing some of these here as well.
The Question:
I want to make a command that either gives a yes or no reply. I want one reply to happen more frequently than the other. 95% of the time it would pick “yes” and only 5% pick “no”. Do you know if this is possible with StreamElements or Nightbot? Thanks in advance. (User then indicated a preference for StreamElements, so I’m starting there)
The Answer:
So the goal here is a command that has a 95% chance of returning Yes. We can generate a random number easily enough with $(random.number). However, StreamElements won’t let us do anything with this number other than output it, so that’s not going to work.
By the way, I’ll assume that you already have StreamElements set up and working. If you haven’t done this yet, you can watch my setup video here and there will be a text-and-screenshot blog version post of the tutorial as well.
I began just by digging through the variable and function documentation for the StreamElements chatbot, looking for something that’ll do most of the work for me. This can be found by clicking Chatbot -> Chat commands and then there is a Link at the top called “Command Variables”
I already know what I’m looking for and am pretty aware of the limitations of StreamElements, so I wanted to explore the functions for random results on this page.
Scrolling down I found the $(random.pick) chatbot function. We used it in this video to do random output based on a predetermined list of phrases or words. Maybe we can just kind of trick it to do what we want by having 19 of the random options be yes, and 1 of them be no.
So click “custom commands” up top and set up a new command.
I’ll just make it be !test95 for now as the command itself.
For the message content, we’ll put some text that can be changed later, and then the result of our yes/no pick:
The result is $(random.pick 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'yes' 'no')
Once we save, we can go test over in chat and see if it works, and it does! You can do whatever you want with the cooldowns and moving the surrounding text around so that it says what you want, as long as you keep the message response under 500 characters total.
So there you have it! A simple weighted random response in StreamElements using only the built-in functionality of StreamElements Chatbot.
Enjoy, and as always please let me know if you have any questions or new ideas!
Check out the StreamElements category for more guides on how to do cool things with the StreamElements chatbot.