admin管理员组

文章数量:1336321

I'm making a user info mand, and I've e 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 mand. 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?

I'm making a user info mand, and I've e 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 mand. 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?

Share asked Aug 31, 2020 at 15:28 PandiconPandicon 4303 gold badges17 silver badges38 bronze badges 1
  • The problem is that it is getting the creation date of the guildmember, not the user's account. So it's just showing when they joined. You need to make a separate variable for the discord user object instead and get the creation date of that. – Levi_OP Commented Aug 31, 2020 at 15:41
Add a ment  | 

2 Answers 2

Reset to default 4

GuildMember has no property called createdAt, only joinedAt.

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

moment(userinfoget.user.createdAt)

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

本文标签: javascriptHow to get the date an account was created at discordjs v12Stack Overflow