From 8b012829c15151ab0014fe653493cef401cead4a Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Mon, 8 Apr 2024 12:40:23 +0200 Subject: [PATCH] Blame last.fm if there is an error --- util/lastfm/getCurrentScrobble.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/util/lastfm/getCurrentScrobble.js b/util/lastfm/getCurrentScrobble.js index 2d1f49b..6d3eb23 100644 --- a/util/lastfm/getCurrentScrobble.js +++ b/util/lastfm/getCurrentScrobble.js @@ -22,7 +22,13 @@ module.exports = async function(userID, guild) { .then(response => response.json()) .then(data => { let scrobble = {}; - let track = data.recenttracks.track[0]; + let track; + try { + track = data.recenttracks.track[0]; + } catch (error) { + scrobble.error = true; + resolve(scrobble); + } scrobble.artist = track.artist["#text"]; scrobble.song = track.name; scrobble.album = track.album["#text"]; @@ -38,6 +44,10 @@ module.exports = async function(userID, guild) { reject(error); }); }); + if(scrobble.error){ + sendText.text = "Last.fm is probably having problems. Try again later."; + return sendText; + } const embed = new Discord.MessageEmbed() .setAuthor(`Now playing - ${nickname}`, user.user.avatarURL({ dynamic: true, size: 4096 })) .setThumbnail(scrobble.cover)