0

I am trying to make a leaderboard with quick.db and I want it to go through all the variables its golding and grab all the variables starting with money_${message.guild.id}_ and give back the rest of the var name and it's amount

let list = []

db.all().forEach(elem => {        
  if(elem.startsWith(`money_${message.guild.id}_`)) {
     board.push(list);
  }
});

message.channel.send(list.join("\n"))

The error I'm getting is elem.startsWith isn't a function

shawn
  • 42
  • 8
  • You repeated your code 3 times in your code block which I'm guessing was accidental, also for your description don't capitalize every word, only do that for titles. Edited it now so don't worry but in the future keep it in mind –  Jul 23 '20 at 21:55
  • 1
    The error clearly says it all, `elem.startsWith` isn't a function which means it's not a string. Log what `elem` is and problem solve, also no where in your code section are you actually pushing to `list`, you are only pushing `list` to `board` –  Jul 23 '20 at 21:59

1 Answers1

0

i got a way for it to work

const db = require("quick.db");
const Discord = require('discord.js');

module.exports.run = (client, message, args) => {
    var roles = [message.Guild.cache.roles.array()];
    var rolesAmount = roles.length;
  //   
    let mes = [];
  
    for (let i = 0; i < rolesAmount; i++) {
      var amount = db.fetch(`roles_${message.guild.id}_${roles[i].id}`);
  
      if (amount == null) return;
      if (amount == "revoved") return;
  
      mes.push({ name: roles[i].user.username, amount: amount });
    }
  
    mes.sort((a, b) => b.amount - a.amount);

    var realArr = []

    mes.forEach(m => realArr.push(`${m.name} - ${m.amount}`));
    var finalLb = realArr.join("\n")

    let embed = new Discord.MessageEmbed()
    .setTitle(`**${message.guild.name}** LeaderBoard`)
    .setDescription(finalLb)
    .setColor("FFFFFC")

    message.channel.send(embed)
};
shawn
  • 42
  • 8