NightDev Community Forums

urlfetch with an argument?

Hey there!
So I have this command that fetches json from a url and reads a certain property:

try {
r = JSON.parse(
$(urlfetch json )
r ? Current game: ${r} : “Not currently in a game”
} catch(e) {e}

This works, but I want to pass in the user for an argument as well as the property in which to read. So instead of “!command” it would be “!command thibault playing”. I know you can use $(1) and $(2) to get the first and second argument but no matter what I try it seems to give me the literal string “$(1)” or an error.

Does anyone know how to get this done? Thanks.

Hi, here is a command I made for you:

!addcom !command -a=_!command $(eval A=$(urlfetch json;try{m=decodeURIComponent("$(querystring)").match(/(\S+)\s+(\S+)/);m?(a=m[2].toLowerCase(),(a in A)?`> ${encodeURIComponent(m[1])} ${A[a]}`:`A ${Object.keys(A).join(', ')}`):'C'}catch(e){`${e}`.slice(0,400)})

!addcom _!command $(eval F=$(urlfetch json;try{q=decodeURIComponent("$(querystring)"),s=q.split(" ")[0],">"==s?(r=`$(urlfetch json$(2))`.replace(/\r\n/g," "),r.match(/^[A-Z]/)?r.match(/404/)?"User not found":r:(p=q.split(" ")[2],v=p.split(".").reduce((a,b)=>a[b],JSON.parse(r)),p in F?F[p](v):v)):"C"==s?"Ex: !command thibault playing":"A"==s?`Attributes: ${q.match(/\S+ (.+)/)[1]}`:"Use !command"}catch(a){`${a}`.slice(0,400)})


My example configuration is hosted on Pastebin:
Visit this link and copy the text. Go to, paste the text, make your modifications, and create the new paste. Now use your new paste ID (found in the URL bar) to replace my example configuration’s paste ID in both !command and _!command.

The A configuration object defines which attributes are supported by the command and the properties to which they map.
playing: 'playing' means that !command thibault playing will use the playing property.
currentgame: 'playing' means that !command thibault currentgame will also use the playing property.

The F configuration object specifies custom formatting for properties.
playing: gameUrl => gameUrl ? `Current game: ${gameUrl}` : 'Not currently in a game' specifies a function to format the playing property value.

1 Like

Exactly what I wanted. Thanks so much!