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

Asked Apr 3, 2023·1 reply·Last activity 3 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.

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 @member"

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

1 reply