I was looking for a solution that would allow me to time-controlled messages can be posted in the chat,
but not the respective message, e.g. every 30 minutes and depending on written chat lines, but the first
Message, after 15 minutes the next one, etc. You can do this with the Streamer.bot and implement a bit of code 🙂

For all bots you can timer but it is always difficult to find the right time intervals for
to find the messages so that several do not come at once and eventually the whole chat is only
out of Bot messages exists if you have too many of them.

That's why I'm going to show you today how it's possible to simply post the next message every 15 minutes (in my case).

Step 1: Download Streamer.bot and link your Twitch account

I have already explained how this works in this tutorial shown, just follow the Steps 1 and 2.

Step 2: Create files

Create two text files (preferably in the data subfolder of the Streamer.bot directory):

  • messages.txt – Here you insert your desired bot messages (one message per line)
  • currentIndex.txt – Here you simply enter a “0” and save (just the number without quotation marks etc.)

Step 3: Create action and trigger

Get a new one Action called “Messages” (or your desired name):

Streamer.bot Action

Get a new one Timed Action with the desired time in seconds:

Streamer.bot Timer

Adds the Timed Action as Trigger for the “News” action:

Streamer.bot Trigger

4. Create sub-actions

Right-click the code sub-action: Core -> C# -> Execute C# Code to.
Insert the following code here:

using System;
using System.IO;

public class CPPHInline
{
public bool Execute()
{
// Checks if OBS is streaming
if (ObsIsStreaming())
{
// Paths to the files
string messagesFilePath = @"C:\Users\Mike\Documents\Streamer.bot-x64-0.2.2\data\messages.txt„; // Adjust the path
string indexFilePath = @“C:\Users\Mike\Documents\Streamer.bot-x64-0.2.2\data\currentIndex.txt„; // Adjust the path

// Read messages from the file
string[] messages = File.ReadAllLines(messagesFilePath);

// Read current index from file
int currentIndex;
if (File.Exists(indexFilePath))
{
currentIndex = int.Parse(File.ReadAllText(indexFilePath));
}
else
{
currentIndex = 0;
}

// Select message based on the current index
string message = messages[currentIndex];

// Increase and reset index if necessary
currentIndex = (currentIndex + 1) % messages.Length;

// Save new index
File.WriteAllText(indexFilePath, currentIndex.ToString());

// Print message (or send to the bot)
CPH.SetArgument("output", message);

return true;
}
else
{
return false;
}
}

public bool ObsIsStreaming(int connection = 0)
{
// Uses the Streamer.bot API to check the streaming status
return CPH.ObsIsStreaming(connection);
}
}

Adjust the paths to your 2 files messages.txt and currentIndex.txt (preferably in the data directory for rights reasons)

This code first checks whether the Stream online so that the messages are not posted when you are just crafting 🙂

For the Test you can simply delete the line “if (ObsIsStreaming())" to "if (!ObsIsStreaming())“ to turn the whole thing around and the action
starts when the stream is offline. Don't forget to change it back, of course.

Then the two files are read, the index is increased by 1 and the respective message is stored in a variable “output“ saved.

Now right-click to create another sub-action Twitch -> Chat -> Send Message to Channel to.

As a message you simply enter “%issue%” (without quotation marks) or “/me %output%“ so that the message appears in the color set on Twitch.
I split it up so you don't have to work directly in the code.

That's it, now you have a small code that will show you your Bot messages posts in Twitch chat
and in the messages.txt You can easily maintain these messages in this file.

I hope you enjoy streaming 🙂

All tutorials


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *