使用 quickdb 将排行榜数据显示到嵌入中

时间:2021-06-13 22:59:06

标签: node.js discord.js

每当我尝试显示某人拥有的现金数量的排行榜数据时,它都会在前 10 名用户中列出的每个姓名上方添加 addField 标题,而不是仅在同一标题下列出前 10 名中的每个人。< /p>

current output
ideal output

let balancecash = db.startsWith(`cash_${message.guild.id}`, { sort: '.data' }).slice(0, 10)
      
    const formatCash = cash => {
      if (cash < 1e3) return cash;
      if (cash >= 1e3 && cash < 1e6) return +(cash / 1e3).toFixed(1) + "K";
      if (cash >= 1e6 && cash < 1e9) return +(cash / 1e6).toFixed(1) + "M";
      if (cash >= 1e9 && cash < 1e12) return +(cash / 1e9).toFixed(1) + "B";
      if (cash >= 1e12) return +(cash / 1e12).toFixed(1) + "T";
    };
      const cembed = new MessageEmbed()
        .setAuthor(`Displaying Cash Leaderboard :: [ ${message.guild.name} ]`)
        .setColor(config.Color)
              
    for (let i = 0; i < balancecash.length; i++) {
          let user = bot.users.cache.get(balancegems[i].ID.split('_')[2]).tag
          let loc = `\`${i+1}\` \n`
          let balancec = `\`formatCash(balancecash[i].data)\``
          cembed.addFields({name: "Place", value: loc, inline: true},
                           {name: "Top 10", value:`\`${user}\` \n`, inline: true},
                           {name: "Balance", value: balancec, inline: true})    
          
      };
    ```

0 个答案:

没有答案