Append Command with random response

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

$(eval a=$(urlfetch json;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.

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";b=a.split("~").filter(c=>c!="");a[0].charAt(0)=="~"?b[Math.floor(Math.random()*b.length)]:"No favorite found")
1 Like

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