[SOLVED] Command that makes Nightbot randomly choose one query

Does anyone know how I would create a command that causes Nightbot to randomly pick one of the queries given, each with an equal chance of being picked—say, with five being the maximum (or at least as many that can fit in a 200-character YouTube message)?

For example, if someone were to use !choose chocolate vanilla strawberry mint cookiedough, Nightbot would randomly pick one of these queries, such as “strawberry” or “cookiedough.”

I could make such a command by making a command with a random response from a list of, say, five responses, but I’m not sure how I’d make it so that a response isn’t selected if there’s no query for it. For instance, I’d still want the command to work if someone only puts two queries.

Any help is greatly appreciated.

@Dimentive

!addcom -cd=5 !choose $(eval a=decodeURIComponent(`$(querystring)`).split(` `);a[0]?a[Math.floor(Math.random()*a.length)]:` `)

Type !choose then a list of choices separated by spaces.

1 Like

Thank you so much, Rocketto!

Is there a limit to how many many items can be in the list? Also, if I make the split a comma instead, the items in the list can include spaces, correct?

There is no limit.

And yes.

1 Like

Thank you so much!

Do you know if it would be possible to essentially combine the !8ball command with this !choose command and have a command that selects a random prefix from a list in a Pastebin paste followed by the randomly picked query?

For instance, if one were to use !choose PS4, XB1, Switch, Nightbot could say, “I prefer Switch,” where “I prefer” is one of the randomly selected responses from the Pastebin paste.

I tried this, among a few other syntaxes, but nothing worked, which isn’t surprising as I barely know anything about JavaScript:

!addcom -cd=5 !ask $(eval a=$(urlfetch https://pastebin.com/raw/WURvJ4MR).split(;);decodeURIComponent($(querystring))?a[Math.floor(Math.random()*a.length)]: + decodeURIComponent($(querystring)).split(, );a[0]?a[Math.floor(Math.random()*a.length)])

!addcom -cd=5 !ask $(eval function r(x){return x[Math.floor(Math.random()*x.length)];}a=$(urlfetch json https://pastebin.com/raw/WURvJ4MR).split(`;`);b=decodeURIComponent(`$(querystring)`).split(`,`);b[0]?r(a)+` `+r(b):` `)
1 Like

Amazing, thanks! Would it be possible to make it 200 characters or shorter for YouTube, though? This is 217 characters:

!a !choose $(eval function r(x){return x[Math.floor(Math.random()*x.length)];}a=$(urlfetch json https://pastebin.com/raw/C6EQpuj0).split(`;`);b=decodeURIComponent(`$(querystring)`).split(`, `);b[0]?r(a)+` `+r(b):` `).
!a !choose $(eval r=x=>x[Math.floor(Math.random()*x.length)];a=$(urlfetch json https://pastebin.com/raw/C6EQpuj0).split(`;`);b=decodeURIComponent(`$(querystring)`).split(`,`);b[0]?r(a)+` `+r(b):` `).
1 Like

It only seems to work with a few queries unlike on Twitch.

Could you provide screenshots of test cases?

1 Like

Never mind. It does seem to work. I suppose it was because of the cooldown as others were also using the command.

Thank you so much for all the help! :blue_heart:

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