Can you help me with this custom nightbot command plz

Asked Oct 4, 2022·3 replies·Last activity 3 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 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?

3 replies

Hey @Witty Pig!

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!')

@Polar Cat 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:

javascript
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!')