Reputation: 364
Here's my code:
const userEmbed = new Discord.MessageEmbed()
.setAuthor(mentionedUser.username, mentionedUser.displayAvatarURL())
.addFields(
{ name: 'Created', value: mentionedUser.createdAt.toUTCString(), inline: true },
{ name: 'Joined', value: mentionedUser.joinedAt, inline: true }, << This line >>
)
.setColor('#05e6ff')
.setTimestamp()
.setFooter(`ID: ${mentionedUser.id}`)
The mentionedUser var is just the user you mentioned (if none the mentionedUser is the author of the message/command)
Upvotes: 0
Views: 78
Reputation: 614
You can fetch the GuildMember for the mentionedUser like so:
const member = await message.guild.members.fetch(mentionedUser);
You can then get their joinedAt Date with member.joinedAt
.
Understanding the difference between a user and a member is helpful in this situation. A GuildMember is a User that is in a Guild (server). You can get the user of a GuildMember trivially, but you need both the User and a Guild to get the required GuildMember.
Upvotes: 1
Reputation: 6710
As user15517071 stated, .joinedAt
is a GuildMember property and not a User property. To get the GuildMember property you can either
A: Grab the mentioned member object
// Instead of
const mentionedUser = message.mentions.users.first();
// Do
const mentionedMember = message.mentions.members.first();
B: Given the User Object, Fetch Using The ID
let memberObj;
message.guild.members.fetch(mentionedUser.id).then(res => memberObj = res);
// You can also use async/await, or work inside the scope of .then(...)
Upvotes: 2