Get a random user from chat (PASTEBIN)

Asked Aug 20, 2021·13 replies·Last activity 5 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.

13 replies

You can’t define nightbot variables like that define it outside the urlfetch then replace it afterwards.

how do I define the URL fetch outside? I saw example of where people were replacing @(user) but the url seems like it might be different.

how do I define the URLfetch outside?

Here’s example:

$(eval a=`$(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel))`;b=$(urlfetch json pastebin_link).split(`Splitting_Character`);b[Math.floor(Math.random()*b.length)].replace(`USER`,a))

So instead of the urlfetch in the command have it be USER all caps or any word that you don’t use anywhere else.

If you need me to elaborate more just say.

Hey @Lively Camel!

There are a lot of topics that cover this already, here's one, please use the search bar before opening a new ticket.

When I try this:
!commands add !butter $(eval a=$(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel));b=$(urlfetch json pastebin_link).split(Splitting_Character);b[Math.floor(Math.random()*b.length)].replace(USER,a)) $(user) $(eval a="$(urlfetch json https://pastebin.com/raw/2ULccb6v)%22.split(%22;%22);a[Math.floor(Math.random()*a.length)])
the output is:
Unexpected identifier Criminateee Invalid or unexpected token

Well I presumed you knew how to fill in the blanks in the command. Like replacing pastebin_link and splitting_character the code should work also why is there a second eval? You can also check out what @Polar Cat said if you need it to all be pre made for you.

So, I assume in your Pastebin are the different possible responses Nightbot can pick from, first you'll want to fix those a bit:

`${u} has spread a load of butter on ${r}.`
`${u} has buttered ${r}'s buns.`
`${u} has let ${r} hold their stick of butter!`

Now, nowhere in your code you make Nightbot pick the response, here's how I'd do it:
(this is the code that goes in your Pastebin)

const responses = [`${u} has spread a load of butter on ${r}.`,
`${u} has buttered ${r}'s buns.`,
`${u} has let ${r} hold their stick of butter!`];
responses[Math.floor(Math.random() * responses.length)];

And finally, we need to fix the rest of your code, your text variables must be marked as such:

!addcom !butter $(eval r='$(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel))'; u='$(user)'; $(urlfetch json https://pastebin.com/raw/2ULccb6v))

Thank you! How would I add a filter to it?

Filter out users from the randomly picked ones? You should have mentioned it sooner, also, you could have found the solution by searching for random user filter in the forums:

(link expired)

Basically, replace r='$(urlfetch http://2g.be/twitch/randomviewer.php?channel=$(channel))'; with:

r=$(urlfetch json http://tmi.twitch.tv/group/user/$(channel)/chatters).chatters;a=r.broadcaster.concat(r.vips,r.moderators,r.staff,r.admins,r.global_mods,r.viewers).filter(n=>![`$(user)`,"Nightbot","UnwantedName3"].some(o=>n.toLowerCase()==o.toLowerCase()));a.length?r=a[Math.floor(Math.random()*a.length)]:r="No chatters";

and don't forget to replace the fields [$(user),"Nightbot","UnwantedName3"] by what you want to filter out.

It says that c is not defined? Is that because of c.vips, c.moderators, c.staff, etc?

Ah, sorry, I modified it in a hurry, I had a meeting, and I missed some stuff, I updated the code, it should work fine now.

To answer your second question: yes.

Didn't find your answer? The community is on Discord.

Ask on Discord