Need help with the nightbot command

Asked Jul 24, 2021·2 replies·Last activity 5 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.

i need 1 message for streamer and 3 random messages for any user
$(eval if("$(query)"=="streamer""$(query)"=="@streamer" "$(query)"=="@Streamer"){"$(query) message $(user)👺"}else{var u=["$(user) msg1 $(query) ","$(user) msg2 $(query)","$(user) msg3 $(query)"];u[Math.floor(Math.random() * sayings.length)]})
how to write it correctly

2 replies

Hey @Stellar Rooster!

It seems to me that apart from the wrong quotes “” surrounding the third $(query) and the first comma in your list of random messages, it should work. JavaScript only supports `` '" ``, pay attention to your quotes when you write code. Wrong quotes, and the fact that sayings is no declared, you should have used u there, you could also have replaced u.length by 3` since you know the length of the array and that it's fixed.

In the meantime, here's a fix with improvements to make it more efficient:

$(eval q=`$(query)`.replace(`@`,``).toLowerCase(); r=[`RANDOM_MESSAGE_1`,`RANDOM_MESSAGE_2`,`RANDOM_MESSAGE_3`]; q==`$(channel)`?r=`STREAMER_MESSAGE`:r=r[Math.floor(Math.random()*r.length)]; `$(user) ${r} ${q}`)