From 69872ba0d1eac435f4fdcce17a5eb679687eebb9 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Sun, 7 Sep 2025 07:49:10 +0200 Subject: [PATCH] Add artist count check to getTopArtists --- util/lastfm/getTopArtists.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/lastfm/getTopArtists.js b/util/lastfm/getTopArtists.js index 40cbe3f..c8befa2 100644 --- a/util/lastfm/getTopArtists.js +++ b/util/lastfm/getTopArtists.js @@ -77,7 +77,8 @@ module.exports = async function (userID, option, guild, compatibility=false) { fetch(`https://ws.audioscrobbler.com/2.0/?method=user.gettopartists&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 artist = {} let currentArtist = data.topartists.artist[i]; artist.name = currentArtist.name;