In my quest to create a list of the top servers based on member count, I have come up with this code snippet:
const embed = new Discord.MessageEmbed()
.setAuthor({ name: `Top Server's`, iconURL: client.user.displayAvatarURL()})
.setColor('#545db8')
for (i = 0; i < 3; i++) {
let guild = client.guilds.cache.sort((a, b) => b.memberCount - a.memberCount).array()[i];
embed.setDescription(`**${i + 1}. ${guild.name}** \n \n Member count: \`${guild.memberCount}\` \n ID: \`${guild.id}\`\n Server Age: <t:${parseInt(guild.createdAt / 1000)}:R>`)
embed.setThumbnail(guild.iconURL())
msg.channel.send({ embeds: [embed] })
}
However, I encountered an error:
TypeError: client.guilds.cache.sort(...).array is not a function
I had successfully used this code in v12, but after switching to v13, errors started appearing. Despite searching through the discord.js documentation, I couldn't find a solution.