'displays as undefined if person dosen't chat discord js v12

Image of users displaying as undefined I wan't to display usernames instead of pinging user in the leaderboard embed? At this point i have no idea what to do i asked people to help and couldn't figure it out. Image it says undefined until member chats.

Leaberboard command file

         let UserJSON = JSON.parse(Fs.readFileSync("./DataBase/users.json"));
        var Sorted = Object.entries(UserJSON).sort((a, b) => b[1].money- a[1].money);
        if (Sorted.length > 10) Sorted = Sorted.slice(0, 10);

        var LBString = "";
        Sorted.forEach(user => {
            LBString += `${client.users.cache.find(u => u.id == user[0])} - ${user[1].money}\n`;
        });
        var LBEmbed = new Discord.MessageEmbed()
            .setColor('#FFFFFF')
            .setTitle("**Coins Leaderboard**")
            .setDescription(LBString);
        message.channel.send(LBEmbed);
        client.channels.cache.get('941016208940077086').send(`${message.author.username} has used $coinslb`)


//users.json file
{"599675959888707594":{"money":492,"lastbeg":1644580691540,"lastwork":1644580757380},"617797297924866093":{"money":0,"lastbeg":0,"lastwork":0}}

I want the leaderboard to display usernames not @ them in the embed



Solution 1:[1]

After user[0]), put .username to get only the username, like this:

LBString += `${client.users.cache.find(u => u.id == user[0]).username} - ${user[1].money}\n`;

Also, it shows undefined when they haven't chatted before because they aren't in your database. You could get the guild (server) you're in and fetch the member by ID, instead of from cache:

guild.members.fetch('user_id_here').username;

Solution 2:[2]

I noticed that if you add it AFTER there is anything in users.json it will be displayed as undefined so when you add the .username you need to reset ur users.json

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 LuisAFK
Solution 2 AnyBananaGAME