diff --git a/util/lastfm/getTopAlbums.js b/util/lastfm/getTopAlbums.js index b87a403..76b0f24 100644 --- a/util/lastfm/getTopAlbums.js +++ b/util/lastfm/getTopAlbums.js @@ -77,7 +77,8 @@ module.exports = async function (userID, option, guild, compatibility=false) { fetch(`https://ws.audioscrobbler.com/2.0/?method=user.gettopalbums&user=${lastfmUsername}&period=${option[0]}&api_key=${process.env.LAST_FM_API_KEY}&format=json`) .then(response => response.json()) .then(data => { - for(let i = 0; i < 10; i++){ + const maxIterations = data.topartists.artist.length >= 10 ? 10 : data.topartists.artist.length; + for(let i = 0; i < maxIterations; i++){ let album = {} let currentAlbum = data.topalbums.album[i]; album.artist = currentAlbum.artist.name; diff --git a/util/lastfm/getTopTracks.js b/util/lastfm/getTopTracks.js index 1f8e7c2..9799e64 100644 --- a/util/lastfm/getTopTracks.js +++ b/util/lastfm/getTopTracks.js @@ -78,7 +78,8 @@ module.exports = async function (userID, option, guild, compatibility=false) { fetch(`https://ws.audioscrobbler.com/2.0/?method=user.gettoptracks&user=${lastfmUsername}&period=${option[0]}&api_key=${apiKey}&format=json`) .then(response => response.json()) .then(data => { - for(let i = 0; i < 10; i++){ + const maxIterations = data.topartists.artist.length >= 10 ? 10 : data.topartists.artist.length; + for(let i = 0; i < maxIterations; i++){ let track = {} let currentTrack = data.toptracks.track[i]; track.artist = currentTrack.artist.name;