Pandicon
Pandicon

Reputation: 430

How to get the date an account was created at discord.js v12?

I'm making a user info command, and I've come to trying to show when the account was created. The bot responds to &profile {user ping/user ID}, if there are no arguments, it shows info about the executer of the command. My code looks like this:

const { DiscordAPIError } = require("discord.js");
const Discord = require('discord.js');
const moment = require('moment');

module.exports = {
    name: 'profile',
    description: "The bot will return the info about the user",
    execute(message, args){
        let userinfoget = message.mentions.members.first() || message.guild.members.cache.get(args[0]) || message.guild.member(message.author)

        const embed = new Discord.MessageEmbed()
        .setColor('#DAF7A6') // or .setColor('RANDOM')
        .setAuthor(`${userinfoget.user.tag}`, userinfoget.user.displayAvatarURL())
        .addFields(
            {name: `User ping`,
            value: `<@${userinfoget.id}>`}
        )
        .addFields(
            {name: `User ID`,
            value: `${userinfoget.id}`}
        )
        .addFields(
            {name: 'Joined server',
            value: moment(userinfoget.joinedAt).format('LLLL')}
        )
        .addFields(
            {name: 'Joined Discord',
            value: moment(userinfoget.createdAt).format('LLLL')}
        .addFields(
            {name: 'Online Status',
            value: `${userinfoget.presence.status}`}
        )
        .setFooter('Bot made by mkpanda')
        message.channel.send(embed);
        
    }
}

The time when the user joined the server is displayed correctly, but the account creation is always the current time. Any way to fix it?

Upvotes: 1

Views: 15157

Answers (2)

Agastya Sandhuja
Agastya Sandhuja

Reputation: 11

this is late but just in case someone else sees this: the client id is based of their creation date so you can easily convert it to a unix timestamp

Upvotes: 1

Jakye
Jakye

Reputation: 6625

GuildMember has no property called createdAt, only joinedAt.

You can only get the createdAt property from the User object.

moment(userinfoget.user.createdAt)

Upvotes: 4

Related Questions