Hi there, pretty new to this but maybe someone can help.
I’ve formulated the below command for nightbot, that fetches the users last csgo faceit match details, but the command returns Invalid Variable.
The url returns json which I have then attempted to format into a sentence, the reason why I’m using “[0]” is because the json contains an array of matches, and I only need the details of the first in the array.
$(lfm = $(urlfetch json http://api.satont.ru/faceit?nick=lawsn));jlfm=JSON.parse(lfm);'lawsn's last faceit match on ${jlfm[0].map} ended ${jlfm[0].teamScore} [${jlfm[0].result}]. ${jlfm[0].kills}-${jlfm[0].deaths} KD (${jlfm[0].kd} K/D), HS (${jlfm[0].hs.percentage})')
$(eval let lfm=$(urlfetch json http://api.satont.ru/faceit?nick=lawsn);let jlfm=JSON.parse(lfm);`lawsn's last faceit match on ${jlfm[0].map} ended ${jlfm[0].teamScore} [${jlfm[0].result}]. ${jlfm[0].kills}-${jlfm[0].deaths} KD (${jlfm[0].kd} K/D), HS (${jlfm[0].hs.percentage})`)
Have you checked the structure of the response?
You are trying to access the array directly, however the last matches are stored in jlfm.latestMatches
try accessing the data that way, for example: jlfm.latestMatches[0].map
Ok modified again, but still throwing this same Unexpected token error.
$(eval let lfm=$(urlfetch json http://api.satont.ru/faceit?nick=lawsn);let jlfm=JSON.parse(lfm);`lawsn's last faceit match on ${jlfm.latestMatches[0].map} ended ${jlfm.latestMatches[0].teamScore} [${jlfm.latestMatches[0].result}]. ${jlfm.latestMatches[0].kills}-${jlfm.latestMatches[0].deaths} KD (${jlfm.latestMatches[0].kd} K/D), HS (${jlfm.latestMatches[0].hs.percentage})`)
Yeah thats almost right, the urlfetch part should be inside quotes, since it’s a string. You can parse it directly without assinging a new var for it:
$(eval let jlfm=JSON.parse(`$(urlfetch json http://api.satont.ru/faceit?nick=lawsn)`); `lawsn's last faceit match on ${jlfm.latestMatches[0].map} ended ${jlfm.latestMatches[0].teamScore} [${jlfm.latestMatches[0].result}]. ${jlfm.latestMatches[0].kills}-${jlfm.latestMatches[0].deaths} KD (${jlfm.latestMatches[0].kd} K/D), HS (${jlfm.latestMatches[0].hs.percentage})`)