Grabbing a single message from chat

I’m trying to set up a chat box on my stream that will randomly pick one message from all the messages received in the last 60 seconds (if any) and display it on my stream.

I know there are chatbots out there with a lot of functionality - maybe one of them could mirror a message every 60 seconds or so to a second chat room and I could display that?

Any other ideas or suggestions on how I might do something like this?

Not sure if you’re asking if something exists or how one would go about doing it but to steer you in the right direction, the simplest/fastest way possible would be to use NodeJS, and the tmi.js Library.

After you setup the library and listen to the channel you want to it’s as simple as:

let messArray = [];

client.on("chat", function (channel, userstate, message, self) {
  // Don't listen to my own messages..
  if (self) return;
  messArray.push({user: userstate.username, mess: message});

var _resetInterval = setInterval(() => {
}, 60000);

function setMessage() {
  let ranNum = Math.floor(Math.random() * messArray.length);
  let selUser = messArray[ranNum].user; // Save selected user in var
  let selMess = messArray[ranNum].mess; // Save selected mess in var
  this.messArray = []; // Clear array
  console.log(selUser + " " + selMess);
  // Now do whatever you want with the message and user of message stored in vars

Again not entirely sure what you were looking for but cheers!

Hey thanks so much. I was completely lost when I posted this but thanks to your post and a little trial and error I was able to use this to create my own script from this that does exactly what I need. Cheers =)

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.