if(interaction.options.getSubcommand() === "global") { let UserProfiles = await UserSave.find(); let GuildProfile = await GuildSave.findOne({ guildID: interaction.guild.id }); if(!GuildProfile) { GuildProfile = await new GuildSave({ _id: mongoose.Types.ObjectId(), guildID: interaction.guild.id, bank: 50000, shop: [], }).save(); } /*console.log(UserProfile);*/ let embed = await new MessageEmbed() .setTitle(`Baltop - Global`) .setDescription("In this list, the names of the top 10 richest users globally will appear.") .setColor("#FFAB00") .setFooter("Bankex", interaction.client.user.displayAvatarURL({ dynamic: true })) .setTimestamp(); /*var times = UserProfiles.length; var Sorted = UserProfiles.sort((a, b) => a.money - b.money); const rank = UserProfiles.map(v => Sorted.indexOf(v) + 1);*/ /*await console.log(rank[0])*/ const sorted = UserProfiles.sort((a, b) => b.bank - a.bank); for (let i=0; i < (sorted.length > 10 ? 10 : sorted.length); i++) { const user = sorted[i]; let userGuild = await interaction.client.guilds.cache.get(user.guildID); if(!userGuild) continue; let userFtchd = await userGuild.members.fetch(user.userID); if(!userFtchd) continue; console.log(userFtchd) //${userTn.username}${userTn.discriminator} await embed.addField(`#${i + 1}`, `${userFtchd.username}#${userFtchd.discriminator} - \`⌬ ${fNum(user.bank + user.wallet)}\``); } await interaction.reply({ embeds: [embed] });