Access $(User) and $(touser) from $(eval [Javascript]<-Here)

I Startet to with the Nightbot for a friend and im really Interested in the things it can and cant do and
im Currently working on a !battle command that should be used like this “!battle @UserX

the first part works fine but i want to get a random answer out of a paste bin that looks something like this
[“$(user) has hit $(touser)…”,“…”,…]. Now i want to get this random string from my pastebin and replace the $(user) to the real user and same for the touser how can i do that? i tried the .replace method like this:

$(eval  b=$(urlfetch json;
b[Math.floor(Math.random()*b.length)].replace('$(user)', $(user)).replace('$(touser)', $(touser)))

but this tells me in chat that the User is not defined, i also tried to create a method inside oh the eval js script but this wont work in chat because “you cant generate code”.

i also tried to use the decodURIComponents:

$(eval const user =decodeURIComponent("$(user)");
const touser = decodeURIComponent("$(touser)");
const b=$(urlfetch json;
b[Math.floor(Math.random()*b.length)].replace('$(user)', user).replace('$(touser)', touser))

but this also gives me the same error when i try it without the " symbols and with them it does nothing.

i don’t understand how i can access the username as a string or otherwise.

Thanks for any help or advise

Hey @Manu_Add1!

This should help you:

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