Node.js ReplDB Leaderboard
h
1Mage (0)

I'm just wondering if you can create a ReplDB Leaderoard in Node.js.

I understand how to make use the ReplDB but don't know how to make a Leaderboard.

Can anyone help me?

You are viewing a single comment. View All
EpicGamer007 (1752)

@ICUP3339 ohhh, I am sorry, i didnt know that was what you meant. For that, you can probably order them by the score and then the top ten people with the highest score, you just put their name and then their score.

client.on('message', message => {
  if (message.content === botPrefix + 'leaderboard') {
    const embed = new MessageEmbed()
      .setTitle('Leaderboard')
      .setColor(0xff0000)
      .setDescription(getData());
    message.channel.send(embed);
  }
});

function getData() {

  const stats = JSON.stringify(db.get("leaderboard")) // if you will use json for storing leaderboard, if you have different pairs for different users, then just do for(key in client.list("").split("\n"){ client.get("key") }

  stats.orderByValuesDescending() // not a real function, just for showing
  let result = "";
  for(let i = stats.length - 1; i > stats.length - 11; i--) {
    result += stats.keyAt(i) +": " + stats[i];
  }

  return result;
  

}

something like this