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 http://pastebin.com/raw/rb1EZT1r);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 https://pastebin.com/raw/XXXXXXXX))

And inside of your Pastebin:

const randomMessages = [
  'RANDOM_MESSAGE_1',
  'RANDOM_MESSAGE_2',
  //...
  'RANDOM_MESSAGE_N'
]; 

switch (u) {
  case 'USERNAME_1':
    'USERNAME_1_MESSAGE';
    break;
  case 'USERNAME_2':
    'USERNAME_2_MESSAGE';
    break;
  //...
  case 'USERNAME_N':
    'USERNAME_N_MESSAGE';
    break;
  default:
    `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.