const { SlashCommandBuilder } = require('@discordjs/builders'); const { MessageEmbed } = require('discord.js'); const UserSave = require('../models/UserSchema'); const GuildSave = require('../models/GuildSchema'); module.exports = { data: new SlashCommandBuilder() .setName('baltop') .setDescription('List over the richest members of the server'), async execute(interaction) { let UserProfiles = await UserSave.find({ guildID: interaction.guild.id }); 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(`${interaction.guild.name} - Baltop`) .setDescription("In this list, the names of the top 10 richest members of the server will appear.") .setColor("#EFD08C") .setFooter("Disbank", interaction.client.user.displayAvatarURL({ dynamic: true })) .setTimestamp(); var times = UserProfiles.length; var Sorted = UserProfiles.sort((a, b) => a - b); const rank = UserProfiles.map(v => Sorted.indexOf(v) + 1); await console.log(rank[0]) /*await UserProfiles.forEach( async element => { await embed.addField(`#${rank} <@${element.userID}>`, `\`❂ ${element.bank + element.wallet}\``) }); await interaction.reply({ embeds: [embed] });*/ }, };