Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

164
Vistas
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

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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;
about 4 years ago · Juan Pablo Isaza Denunciar

0

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

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda