Once per stream message at specific uptime

I’m new to Nightbot (and streaming in general) so I’m sorry if this has been asked an answered already. I want to set up commands that will run automatically after a certain amount if streaming time has elapsed (specifically, I want a message that “fires” as soon as I go live and several others that display at certain times during the stream). I don’t want the message to repeat until the same time during the next stream so using the Timer feature isn’t quite what I’m looking for.

Thanks in advance for the guidance! :blush:

To do something like that specifically with nightbot would likely require you to use the api to send messages threw the bot when an event triggers. You could potentially do the send message at certain intervals throughout with use of a timer that check how long you’ve been streaming but wouldn’t be entirely exact. It would be a process similar to what’s detailed here. Just instead of followers when u start stream.

1 Like

Hey @AesDraconis!

Yes, of course you can use timers for that, but you have to get creative!

Simply set it up short enough, I recommend the minimum: 5 minutes, and then when the timer runs have it look at the amount of time you’ve been streaming, and only send a message if it’s the right moment of the stream.

You’ll need to use Pastebin, that way you’ll only set up one timer, and you’ll be able to fit all your messages in it.

Code to put in the timer:

$(eval uptime='$(twitch $(channel) "{{uptimeLength}}")'; $(urlfetch json https://pastebin.com/raw/XXXXXXXX))

Code to write in your paste:

const messages = {
	'0000': 'Message at 0 minute of stream time',
	'0035': 'Message at 35 minutes of stream time',
	'0125': 'Message at 1 hour and 25 minutes of stream time',
	'0200': 'Message at 2 hours of stream time',
	'1315': 'Message at 13 hours and 15 minutes of stream time'

const messagesTimestamps = Object.keys(messages);

const findData = (string, regex) => string.match(regex) || '0';
const keepAmount = string => string.split(' ').filter(e => isNaN(e) === false);
const normalizeAmount = string => string.padStart(2, '0');
const arrayToString = array => Array.isArray(array) ? array.join('') : array;

const hourRegex = /\d+\s\bhour/;
const minuteRegex = /\d+\s\bminute/;

const hourData = arrayToString(findData(uptime, hourRegex));
const minuteData = arrayToString(findData(uptime, minuteRegex));

const hourAmount = arrayToString(keepAmount(hourData));
const minuteAmount = arrayToString(keepAmount(minuteData));

const normalizedHourAmount = normalizeAmount(hourAmount);
const normalizedMinuteAmount = normalizeAmount(minuteAmount);

const currentTime = normalizedHourAmount.concat(normalizedMinuteAmount);

let timestamp = [];
messagesTimestamps.forEach(e => {
	if (Math.abs(parseInt(e) - parseInt(currentTime)) <= 5) {

messages[timestamp[0]] || ' ';

• Replace XXXXXXXX in the timer code with the paste ID.
• Feel free to edit the messages in the Pastebin by following exactly the formatting here (of course you can have more than 5 messages); you can change the message times by editing the numbers.
• Make sure the paste is public or unlisted (do not make it private) and that it’s set to never expire.

Please note that it’ll skip messages if your chat isn’t active, messages can also be a bit delayed (by a maximum of 5 minutes).

I recommend setting up a Pastebin account so you can come back later to edit your messages.


Thank you for that replay. I’ll have to learn what all that coding means but it’s a place to start. :blush:

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