Command help for a specific response for certain people and a random response from a list for all others

Hi! I’m very new to this in general but I’ve made good use of this site and Google to muddle through learning the very basics of creating commands with nightbot over the last couple weeks.

I know how to make a command that gives a specific response to specific people and a generic response to any others thanks to this site. I also know how to make a command that gives a random response from a list thanks to this site.

My current trouble is combining the two types of commands. I would like the named people to get specific responses if they use the command and all others to get a randomized response from a list. I am struggling and any help would be greatly appreciated. I will post an example of what i am trying to use below.

!addcom !test $(eval u=$(user); a=$(urlfetch json;a[Math.floor(Math.random()*a.length)])

Hey @Ryan_N!

I’ve already covered this a few times before, for example I found this while searching for “user specific random response”:

Just replace the r array with $(urlfetch json RAW_PASTEBIN_LINK_CONTAINING_AN_ARRAY).

But I understand this doesn’t completely addresses your needs as it’s limiting a bit: only a single username can have a custom response.

If I had to fix your command according to the way you approached it, here’s how I’d write it:

$(eval u = '$(user)'; $(urlfetch json

And inside of your Pastebin:

const randomMessages = [

switch (u) {
  case 'USERNAME_1':
  case 'USERNAME_2':
  case 'USERNAME_N':
    `Hello ${u}! ${randomMessages[Math.floor(Math.random() * randomMessages.length)]}`;

Thank you so much for the help!

1 Like

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