Blame last.fm if there is an error

This commit is contained in:
SileNce5k 2024-04-08 12:40:23 +02:00
parent a8575f6f25
commit 8b012829c1
No known key found for this signature in database
GPG key ID: 961132EB78C8915F

View file

@ -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)