NightDev Community Forums

Custom api that can use $(user) and $(touser)

hey guys i was hoping to get some help on making a custom command for nightbot that i can use from somewhere like pastebin and that nightbot can say who the the command user and who they want to target for example.

‘$(user) attempted to hook $(touser) but $(touser) wriggled free’

so far i can get night bot to randomize the diffrent phrases but i cant quite work out how to do the user and touser part

any help would be very much appreciated

Hey @hoodlumkira!

Assign $(user) and $(touser) to a variable before getting the randomized output.

So for example:

$(eval u=`$(user)`; t=`$(touser)`; r=`$(urlfetch json RAW_PASTEBIN_URL)`.split(`;`); r[Math.floor(Math.random()*r.length)])

And in the Pastebin you’d refer to $(user) and $(touser) to ${u} and ${t} respectively.

Have just tried that and it has unfortunately hasnt carried over its now just displaying ${u} or ${t}
ive tried both the json and php format unless i have chosen the wrong format

heres whats currently written in pastebin

'${u} successfully dragged ${t} down to the basement and hooked them ',
‘${u} attempted to hook ${t} but ${t} wriggled free’,

and heres the code Im running on twitch

!commands add !hit $(eval u="$(user)"; t="$(touser)"; r ="$(urlfetch json https://pastebin.com/raw/56d7H54x) ".split(","); r[Math.floor(Math.random() * r.length - 1)])

To my knowledge the problem is that you should probably be using backticks ` not ’ or "

PotatoEaterLove is onto something.
I think it’s because of the apostrophes ' you used in your Pastebin, you don’t need them as you specify in the command that it’s text with the quotation marks " around the $(urlfetch).

If I do it my way, command:

$(eval u=`$(user)`; t=`$(touser)`; r=`$(urlfetch json https://pastebin.com/raw/XXXXXXXX)`.split(`;`); r[Math.floor(Math.random()*r.length)])

Pastebin:

${u} successfully dragged ${t} down to the basement and hooked them;
${u} attempted to hook ${t} but ${t} wriggled free

It works like a charm:

1 Like

Thanks heaps guys I’ve got it in and running and works well thanks heaps for your help :grin::grin:

1 Like