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

129
Vistas
joinedAtTimeStamp is showing Nan discord.js

I was coding a userInfo command but when I use the command, the joinedAtTimeStamp is showing <t:NaN:R> in the embed. It's the only problem in this code.

My code:

const { MessageEmbed, ContextMenuInteraction } = require("discord.js");

module.exports = {
    name: "userInfo",
    aliases: ["user"],
    permissions: ["SEND_MESSAGES", "ATTACH_FILES"],
    description: "user",

    async execute(message, args, cmd, client, Discord, profileData) {
        const target = message.mentions.users.first();
        if(!args[0]) {
            const response2 = new MessageEmbed()
            .setColor("RANDOM")
            .setAuthor({name: message.author.tag, iconURL: message.author.displayAvatarURL({dynamic: true})})
            .setThumbnail(message.author.displayAvatarURL({dynamic: true}))
            .addFields(
                {name: "ID", value: message.author.id},
                {name: "Joined Server", value: `<t:${parseInt(message.author.joinedTimestamp / 1000)}:R>`, inline: true},
                {name: "Account Created", value: `<t:${parseInt(message.author.createdTimestamp / 1000)}:R>`, inline: true},
                
            );
            message.reply({embeds:[response2]});
        }
        const response = new MessageEmbed()
            .setColor("RANDOM")
            .setAuthor({name: target.tag, iconURL: target.displayAvatarURL({dynamic: true})})
            .setThumbnail(target.displayAvatarURL({dynamic: true}))
            .addFields(
                {name: "ID", value: target.id},
                {name: "Joined Server", value: `<t:${parseInt(target.joinedTimestamp / 1000)}:R>`, inline: true},
                {name: "Account Created", value: `<t:${parseInt(target.createdTimestamp / 1000)}:R>`, inline: true},
            );
            
        message.reply({embeds: [response], ephemeral: true})
    }
}

I am using discord.js v13 and node 16.

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

0

message.author is a User and it doesn't have a joinedTimestamp property, only GuildMembers have. message.member represents the author of the message as a guild member, so you can use that as it will have a joinedTimestamp property.

The reason you see NaN instead of the correct value is because parseInt will return NaN if you try to parse undefined:

console.log('undefined:', parseInt(undefined / 1000, 10));
console.log('3459192421512:', parseInt(3459192421512 / 1000, 10));

The following code should work as expected

.addFields(
  { name: 'ID', value: message.author.id },
  {
    name: 'Joined Server',
    value: `<t:${parseInt(message.member.joinedTimestamp / 1000, 10)}:R>`,
    inline: true,
  },
  {
    name: 'Account Created',
    value: `<t:${parseInt(message.author.createdTimestamp / 1000, 10)}:R>`,
    inline: true,
  },
);

As for target, it's the same issue; message.mentions.users.first() is a User. You could create a new variable, e.g. targetMember and assign message.mentions.members.first(), so it will be a GuildMember:

const target = message.mentions.users.first();
const targetMember = message.mentions.members.first();

And then, just replace target:

.addFields(
  { name: 'ID', value: target.id },
  {
    name: 'Joined Server',
    value: `<t:${parseInt(targetMember.joinedTimestamp / 1000, 10)}:R>`,
    inline: true,
  },
  {
    name: 'Account Created',
    value: `<t:${parseInt(target.createdTimestamp / 1000, 10)}:R>`,
    inline: true,
  },
);

PS: It's a good idea to use the radix in parseInt. That's why I added 10 as the second parameter in parseInt.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Could you verify the type of target.joinedTimestamp?

It could be that the double conversion you are doing here:

parseInt(target.joinedTimestamp / 1000)

destroyed your number.

(You are converting whatever target.createdTimestamp is to number, dividing it by 100 (making it a floating point number) and then discarding the floating point by converting back to int.)

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