Skip to content

Commit 4b834be

Browse files
committed
✨ Add artist URL to embed author attribute
Monstercat API's data is patchy, many releases are missing various attributes meaning we have to check if an attribute is non-null before using it
1 parent affc16d commit 4b834be

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

resources/modules/embed.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,18 @@ module.exports = {
88
const colour = colours[row.Label.toLowerCase()] ?? 'b9b9b9';
99
const CC = await creatorFriendly(releaseJSON, row.Track);
1010
const funcTime = Date.now() - startTime;
11-
// const artistURL = 'https://google.com';
11+
let primaryArtist, artistURL = undefined;
12+
try {
13+
primaryArtist = releaseJSON.Release.Artists.find(a => a.ArtistNumber == 1);
14+
artistURL = `https://monstercat.com/artist/${primaryArtist.URI}`;
15+
} catch (e) {
16+
// maybe log this?
17+
}
1218

1319
const embed = new EmbedBuilder()
1420
.setColor(colour)
1521
.setTitle(`${row.Track}`)
1622
.setURL(releaseURL(row.ID))
17-
.setAuthor({ name: `${row.Artists}` })//, url: `${artistURL}`})
1823
.setDescription(`${licensability[CC]}`)
1924
.setThumbnail(coverURL(row.ID))
2025
.addFields({
@@ -47,6 +52,12 @@ module.exports = {
4752
inline: true
4853
})
4954
.setFooter({text: `Retrieved in ${funcTime}ms.`});
55+
56+
if (artistURL) {
57+
embed.setAuthor({ name: `${row.Artists}`, url: `${artistURL}`})
58+
} else {
59+
embed.setAuthor({ name: `${row.Artists}`});
60+
}
5061

5162
return embed;
5263
}

0 commit comments

Comments
 (0)