Nightbot random response

Hello, can anyone tell how to make nightbot to give a random response (from a set array of different string values) when a user mentions nightbot in the chat? Thank you.

1 Like

Hey @Miro!

This should do the job:

!addcom nightbot $(eval a=[`RESPONSE_1`,`RESPONSE_2`,`RESPONSE_3`];a[Math.floor(Math.random()*a.length)])

Replace the RESPONSES with your text, you can add as many response as you like, just don’t go over 500 characters for the entire command.

And you can add the following command to make sure Nightbot gives a response too if he’s mentioned with the @:

!addcom @nightbot -a=nightbot null
1 Like

Thank you but unfortunately this code only returns the first string each time, in this case Response_1. Can you advise?

This is odd, if you exactly copy/pasted the command I wrote and simply changed the RESPONSES fields, even if you added more by following the syntax, it should work just fine:

Maybe you could post the command you added here if you want me to have a look at it?

It did work indeed! Thank you.

Can I send you a command and tell me why it’s wrong? please

image

Hey @s3b4st14n!

It would be easier for me if you could provide a text version of the command you added, I can’t work on code from a screenshot, especially since Twitch’s new font masks some things, thanks for your understanding.

!addcom !pana $(eval a=[$(user) tienes un 79% de ser mi pana , $(user) tienes un 53% de ser mi pana , $(user) tienes un 0% de ser mi pana , $(user) tienes un 4% de ser mi pana , $(user) tienes un 69% de ser mi pana , $(user) tienes un 100% de ser mi pana , $(user) tienes un 45% de ser mi pana , $(user) tienes un 97% de ser mi pana , $(user) tienes un 62% de ser mi pana , $(user) tienes un 23% de ser mi pana , $(user) tienes un 87% de ser mi pana`];a[Math.floor(Math.random()*a.length)])

That’s what I thought, your code is missing either the quotation marks ", the apostrophes ', or the backticks `. I personally prefer the latter, you need to use any of these to specify text.
Here’s the fix:

!addcom !pana $(eval a=[`$(user) tienes un 79% de ser mi pana`,`$(user) tienes un 53% de ser mi pana`,`$(user) tienes un 0% de ser mi pana`,`$(user) tienes un 4% de ser mi pana`,`$(user) tienes un 69% de ser mi pana`,`$(user) tienes un 100% de ser mi pana`,`$(user) tienes un 45% de ser mi pana`,`$(user) tienes un 97% de ser mi pana`,`$(user) tienes un 62% de ser mi pana`,`$(user) tienes un 23% de ser mi pana`,`$(user) tienes un 87% de ser mi pana`];a[Math.floor(Math.random()*a.length)])
1 Like

Yes now, thank you a lot

1 Like

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