NightDev Community Forums

How to create a !matchmaker command

#1

Hi y’all, I’m trying to make a !matchmaker command that i’ve seen on some other streams but I can’t figure out how to fetch the users in chat to get a random name to pair people together.

So far I have this: /me [user] has been matched with [urlfetch] but i’m not sure what the url is for me to get the list of chatters. Any help would be appreciated.

Thanks

0 Likes

#2

@grumpygrim

Copy and paste this into chat to add a !matchmaker command.

!addcom -cd=5 !matchmaker $(eval try{a=JSON.parse(`$(urlfetch json http://tmi.twitch.tv/group/user/$(channel)/chatters)`).chatters;b=a.broadcaster.concat(a.vips,a.moderators,a.staff,a.admins,a.global_mods,a.viewers).filter(c=>![`$(user)`,`FIRST_USERNAME`,`SECOND_USERNAME`,`ETC`].some(d=>c.toLowerCase()==d.toLowerCase()));`.me $(user) has been matched with `+(b[Math.floor(Math.random()*b.length)]||`nobody. It's lonely in here.`);}catch(e){`Error: ${e.message}`.slice(0,400);})

This command fetches the list of viewers in your channel and selects one at random to pair with the command user. It will output another response if there are no viewers to pick. Take note of this array in the script:

[`$(user)`,`FIRST_USERNAME`,`SECOND_USERNAME`,`ETC`]

These are the array of usernames that Nightbot will filter out of the list before picking a random viewer. The command user is included in this filter so that viewers don’t get paired with themselves. If there are other users you want to filter out (lurkbot viewers or chatbots for example), add them to this list. You can add more users, just as long as you keep each name separated by commas and bounded by backticks as shown above.

0 Likes