Append Command with random response

Asked Aug 19, 2020·1 reply·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.

After seeing this article (link expired), I tried to make nightbot to give me a random response from !favorites using this:

$(eval a=$(urlfetch json https://twitch.center/customapi/quote/list?token=5fedcb87&no_id=1);a.startsWith(~)?a.split(~).filter(c=>c!=`).join(, )[Math.floor(Math.random() * a.length)]:No favorite found.`)

But apparently it give me a random letter, not the entire phrase.

1 reply

The problem is your re joining it and it’s no longer an array so it doesn’t read properly.
This should work fine:

$(eval a="$(urlfetch json https://twitch.center/customapi/quote/list?token=5fedcb87&no_id=1)";b=a.split("~").filter(c=>c!="");a[0].charAt(0)=="~"?b[Math.floor(Math.random()*b.length)]:"No favorite found")