I'm trying to make a !song command with https://nowplaying.tinyrobot.co/
the API url returns something like this:
json{"isPlaying": true,"artists": [{"name": "Ali Gatie","uri": "spotify:artist:4rTv3Ejc7hKMtmoBOK1B4T"},{"name": "Tate McRae","uri": "spotify:artist:45dkTj5sMRSjrmBSBeiHym"}],"albumName": "The Idea Of Her","albumUri": "spotify:album:5SBdHir3OHo2WZN0F3Pnbr","songName": "lie to me","songUri": "spotify:track:4NUgJ9gYHuAhaT3bj9ONh3"}
I wrote this:
javascript$(eval const api = $(urlfetch json https://nowplaying-api.tinyrobot.co/playbackstate?key=REDACTED); `${api.artists[0].name} - ${api.songName} → ${api.songUri.replace('spotify:track:','open.spotify.com/track/')}`)
But there's somethings I'm trying to add but don't know how, I want NightBot to return Not currently playing song when ${api.isPlaying} is set to false, and also if I added ${api.artists[1].name} it will only work with songs that has 2 or more artists, otherwise if the song has only one artist it will return Cannot read properties of undefined (reading 'name')