0

I have a leaderboard command which displays who has the highest balance in the guild. However, a user's account was deleted yesterday and now I'm having problems with my code; as he used to execute the work command and earn money. Now that he's gone I'm getting this error, TypeError: Cannot read property 'users' of undefined. Quick db version: ^7.1.1. If you wish to see the full code, here it is.

       let user = client.users.cache.get(coins[i].client.users.resolve(id).split('_')
            if(user === undefined)
Jhay
  • 83
  • 1
  • 7

1 Answers1

1
const coins = db.all()
    .filter(data => data.ID.startsWith(`coins_${message.guild.id}`))
    .sort((a, b) => b.data - a.data);

let content = "";

for (let i = 0; i < coins.length; i++) {
    const { ID: id, data } = coins[i];

    //uses cache you can change to fetch if you need by client.users.fetch
    //https://discord.js.org/#/docs/main/stable/class/UserManager?scrollTo=fetch
    const user = client.users.cache.get(id.split('_')[2]);

    if (user) content += "```" + `ini\n[ ${i + 1}. ${user} | $${data} ]\n` + "```";
}
  • The code is currently working. However, the list of people's names that have money does not appear on the leaderboard. – Jhay May 18 '20 at 18:32
  • What do you mean exactly? Can you send a picture –  May 18 '20 at 23:40
  • [image](https://imgur.com/a/nwCAKC0) Names and the user's money should be posted on the leaderboard by now because they already have earned money. But nothing shows up. – Jhay May 18 '20 at 23:49
  • This means all of them fail atleast one conditional, you'll have to check, for the first one, after `let content`, log what `coins` is, second after `userClient` log `userClient`, then log id and then finally user. –  May 19 '20 at 00:25
  • I logged `coins` and `userClient` however, `userClient` is returning as undefined. Here's an image of the result. [image](https://imgur.com/a/nPlpsiv) – Jhay May 19 '20 at 01:01
  • Updated the code, this one should work assuming you still get that coins array, I'm not sure how those objects passed though? As they don't start with `coins_${msg.guild.id}`. Or you just changed to `barya_` ig. –  May 19 '20 at 03:03
  • I changed it to `barya_` the embed is being sent, but there's nothing inside. – Jhay May 19 '20 at 04:18
  • You would have to debug again, logging `coins`, ID and all that, this is getting long, and it would be better if you added me on discord if you want further help (Karizma#9456) –  May 19 '20 at 05:49