Can you help me with this custom nightbot command plz

I really liked this command

!addcom hello $(eval const q = ‘$(query)’; q === ‘mate’ ? ‘Hello mate!’ : q === ‘MATE’ ? ‘STOP YELLING!!!’ : ‘Hello!’)

but I need the nightbot to give more than 1 response for every sentence
for example:
if I type in chat “hello mate” the nightbot will respond with one random respond from a variation of responses [RESPONSE_1,RESPONSE_2,RESPONSE_3]
and the same goes for if I type in the chat “hello MATE” it will give another random respond from a set of responses [RESPONSE_4,RESPONSE_5,RESPONSE_6]

is it possible?

Hey @Zoroarid!

Haha, yes, it’s possible:

!addcom hello $(eval const l = ['RESPONSE_1', 'RESPONSE_2', 'RESPONSE_3']; const u = ['RESPONSE_4', 'RESPONSE_5', 'RESPONSE_6']; const r = (a) => a[Math.floor(Math.random() * a.length)]; const q = '$(query)'; q === 'mate' ? r(l) : q === 'MATE' ? r(u) : 'Hello!')
1 Like

@Emily thank you so much, another thing if you don’t mind me asking is can I add a pastebin link instead? in case I reach the 500 character limit.

Yes you can, simply put the following variables in the Pastebin, like so:

const l = ['RESPONSE_1', 'RESPONSE_2', 'RESPONSE_3'];
const u = ['RESPONSE_4', 'RESPONSE_5', 'RESPONSE_6'];
// l variable for lowercase responses
// u variable for uppercase responses

Then your code would look like like this:

!addcom hello $(eval $(urlfetch json https://pastebin.com/raw/XXXXXXXX) const r = (a) => a[Math.floor(Math.random() * a.length)]; const q = '$(query)'; q === 'mate' ? r(l) : q === 'MATE' ? r(u) : 'Hello!')
1 Like

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