How to pick a random option between the sender and the user mentioned

As the topic says I want to pick a random option between the user who used the command and the user he tagged. When I used Stream Elements this worked:

!fight @user
“${random.pick ‘${sender}’ ‘${user}’} won the fight”

But also I’d like to use this as a timer with a list of words/phrases, so the bot sometimes says a random word or phrase I set. In Stream Elements was:

“${random.pick ‘A’ ‘B’ ‘C’ ‘D’}”
So the bot would say one of them when activated.

Thanks for the help

Hey @soyagiraru!

With Nightbot you can leverage the power of JavaScript to do what you want, that means we use $(eval) and Math.random().

For example, to randomly pick between the user who called the command, and the target of the user, you can use:

$(eval users = ['$(user)', '$(touser)']; users[Math.floor(Math.random() * users.length)];)

And to pick a random word/sentence, you’d do it like this:

$(eval strings = ['hello world', 'it\'s Nightbot', 'A', 'B', 'C']; strings[Math.floor(Math.random() * strings.length)];)

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