Nightbot command to pull a random JSON array

I am trying to create a command where I can read a JSON array with multiple properties (for example - prompt, response). I want to be able to get a random prompt response pair from that array and stagger the responses so it feels like a question is asked and then a response is given.

I think I know how to use to stagger the responses, but I am stuck on how to get a random prompt response pair from the JSON array.

Example of what my JSON data looks like:

“prompt”: “Prompt01”,
“response”: “Response01”
“prompt”: “Prompt02”,
“response”: “Response02”
“prompt”: “Prompt03”,
“response”: “Response03”

Example of expected output in the chat:

User: !command
Nightbot: Prompt02
Nightbot: Response02 (after 5-10 seconds)

Thanks in advance for the help!

roughly try this
!addcom !command $(eval x = $(urlfetch json; x[Math.floor(Math.random() * x.length)]))

oh wait i read it wrong
you probably looking for this Nightbot Multiple Messages Command Generator (

I was able to solve this part of the problem already. My problem currently is how to get a random prompt, response pair out from the JSON array. I’m not sure how to get a single item out of that JSON array.

Once I can get that object, I can parse the prompt and response into two eval statements and use to send multiple messages.

i’d say the easiest way would be to get the random number and alias it to a second command with the multiple message generator thing…

got it, thank you - I’ll try and update the thread based on what I’m able to accomplish.

1 Like

yeah, actually i thought about that after i said it… it would actually be easier and less work for nightbot (faster response) if u did the whole json thing in the first command and then have it output just your prompt and response, then the second command just does the timed part with the multiple generator thing