Nightbot random response

Asked Jun 5, 2020·10 replies·Last activity 6 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

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.

10 replies

Hey @Spiffy Rabbit!

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

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?

vB0NBam7Ad.png

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

Hey @Golden Monkey!

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)])

Didn't find your answer? The community is on Discord.

Ask on Discord