Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

158
Views
TypeError: Cannot read properties of undefined (reading 'member')

Can someone help me figure out this error? I really dont know what to do. I tried my best to get rid of this error, but nothing worked. I will be very grateful if you try to help me. This code is supposed to give you basic information about user that you pinged.enter image description here

const Command = require("../Structures/Command.js");

/**
 * @param {Client} client
 * @param {Message} message
 * @param {String[]} args 
 */

module.exports = new Command({
    name: "userinfo",
    description: 'info',

    async run(client, message, args) {
        const user = message.mentions.member.first() || message.member.user.username;
        const member = message.guild.members.cache.get(user.id);

        const embed = new MessageEmbed()
            .setColor('DARK_RED')
            .setAuthor({ name: user.username, iconURL: user.avatarURL({ dynamic: true }) })
            .setDescription("Kdo to je")
            .setThumbnail(user.displayAvatarURL({ dynamic: true }))
            .addFields(
            { name: "Username", value: user.username, inline: true }, 
            { name: "Tag", value: user.discriminator, inline: true }, 
            { name: "Bot", value: user.bot, inline: true }, 
            { name: "Nickname", value: member.nickname || "None", inline: true },
            { name: "Joined:", value: new Date(member.joinedTimestamp()).toDateString(), inline: true },
            { name: "Discord user since:", value: new Date(user.createdTimestamp()).toDateString(), inline: true },
            { name: "Roles count:", value: member.roles.cache - 1, inline: true },

            )

        return message.channel.send({ embeds: [embed] });
    }

})

Im also sharing my simple command handler, because its used in this code.

const Client = require("./Client.js");

/**
 * @param {Discord.Message} message 
 * @param {string[]} args 
 * @param {Client} client 
 */
function RunFunction(message, args, client) {}


class Command {

    /**
     * @typedef {{name: string, description: string, run: RunFunction}} CommandOptions
     * @param {CommandOptions} options 
     */
    constructor(options) {
        this.name = options.name;
        this.description = options.description;
        this.permission = options.permission;
        this.run = options.run;
    }
}

module.exports = Command;
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

One of the following does not contain object:

message.mentions.member or message.member or message.guild.members

Therefore when you try to access i.e. message.mentions.member.first() it fails, because you try to call something like undefined.first()

You should log (or debug) the whole message parameter and see what is actually inside.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!