Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

157
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda