#target.joinedAt is returning to be undefined

31 messages · Page 1 of 1 (latest)

twin robin
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

hallow hollow
#

Show the code where you get the user option

umbral verge
#

use getMember since joinedAt is a property of GuildMember

exotic vale
#

The code there is where it gets the user

exotic vale
umbral verge
#

No, that code is where you tell discord that users should be able to put a user into that option. It‘s not where your bot gets the user from the interaction

umbral verge
exotic vale
crude spokeBOT
#

Despite sounding similar there is a distinct difference between users and members in Discord:
User: global Discord user data (global avatar, username, tag, id)
GuildMember: user data associated to a guild (guild, nickname, roles, voice, guild avatar, etc.)
• Conversion: User ➞ GuildMember | GuildMember ➞ User

exotic vale
#
 const target = interaction.options.getUser('user');
        const guildTarget = guild.members.fetch(target.id)
hallow hollow
#

use .getMember

exotic vale
hallow hollow
#

Show the error

exotic vale
#

.getMember doesnt exist dude

exotic vale
#

this is the error

hallow hollow
#

interaction.options.getMember

exotic vale
hallow hollow
#

And guild isn't defined

hallow hollow
exotic vale
#

@hallow hollow

hallow hollow
#

Show your new code

exotic vale
#
        
    async execute(interaction) {
        const target = interaction.options.getUser('user');
        const guildTarget = interaction.option.getMember('user')
        const exampleEmbed = new EmbedBuilder()
            .setColor(212121)
            .setAuthor({ name: `User info for ${target.tag}` })
            .setDescription('Some description here')
            .setThumbnail(`${target.displayAvatarURL()}`)
            .addFields(
                { name: 'User ID', value: `${target.id}` },
                { name: 'The user has had Discord for:', value: `${timeSince(new Date(target.createdTimestamp))}` },
                { name: 'The user has been in the server for', value: `${timeSince(new Date(guildTarget.joinedAt))}` },
            )
            .setTimestamp()
            .setFooter({ text: `Command issued by ${interaction.user.tag}`, iconURL: ` ${interaction.user.displayAvatarURL()}` });
        return interaction.reply({ embeds: [exampleEmbed], ephemeral: false });
    },
};
#

@hallow hollow

deft tusk
exotic vale
#

oh lol