Could anybody please explain to me, why this doesn’t work with Nightbot? Is a Nightbot command only able to return one line, therefor only giving me the first input?
A bit more info would be nice, what are you trying to do?
It’s not giving you the first input, but the last, after the while completes (and the old $message is overwritten). You can append that message part to another var if you want to output it in one string.
Nightbot only returns the result of the last evaluated variable/method within $(eval) which means, like xgerhard said, it will only return the value of message from when it was last overwritten (from the last iteration of the while loop).
As also previously mentioned, you should therefore append message to another variable for each iteration of the while loop, then return the value of this other variable after the loop ends. This should do it:
You could actually do that in JS by appending a new line (\n) to newMessage in each iteration of the while loop, but Twitch and YouTube chat don’t support line breaks so the $(eval) output would instead look like a rectangular wall of spam.
I have done something similar with urlfetch and the ‘Nightbot-Response-Url’ that Nightbot provides.
The !pyramid command calls a python script in a flask backend, that catches the Nightbot-Response-Url and then posts 5 messages to the Url to create the pyramid.
However, the limitations of the channel/send API (only 5 responses and 5 seconds between each of them) makes the Nightbot pyramids comically slow.