#Explain more

1 messages · Page 1 of 1 (latest)

stoic gale
#

Post the code and full error

raven glen
#
const BaseCommand = require('../../../Structure/BaseCommand')
const { Message, Client, MessageEmbed } = require('discord.js')
const moment = require('moment');
const { TimestampStyles, time } = require('@discordjs/builders')

module.exports = class extends BaseCommand {
    constructor (...args) {
        super(...args, {
            description: "Display's information about a member",
            category: { name: "Information", emoji: ":notebook_with_decorative_cover:" },
            aliases: ['user'],
            appearance: { emoji: ":receipt:" }
        })
    }
    /**
    * @param {Message} msg
    * @param {String[]} args
    * @param {Client} client
    */

    async run(msg, args, client) {
        const target =  msg.mentions.members.last() || await msg.guild.members.fetch(args[0]).catch((e) => { console.log(e); target = null; }) || msg.member

        const GUILD_DATA = await this.client.util.loadGuildConfig(this.client, msg.guildId)
        let GUILD_PREFIX = GUILD_DATA ? GUILD_DATA.SETTINGS[0].PREFIX : this.client.PREFIX_DEFAULT

        console.log(target);
        
        if (!target) {
            msg.channel.send({
                embeds: [
                    new MessageEmbed({
                        author: ({ name: msg.author.tag, iconURL: msg.author.displayAvatarURL({ dynamic: true }) }),
                        description: `Incorrect command usage, *an example is shown below*.\n\`${GUILD_PREFIX}${this.name} [member]\`\n\nArguments -\n\`member\`: *A mentioned member (@User) or user ID (123467890)*`,
                        thumbnail: ({ url: msg.author.displayAvatarURL({ dynamic: true }) }),
                        color: this.client.assets.colors.COLOR_INVISIBLE_EMBED
                    })
                ]
            }).catch(() => { });
            return;
        };

        //const roles = target.roles.cache
        //    .sort((a, b) => b.position - a.position)
        //    .map(role => role.toString())
        //    .slice(0, -1)
        
        const EMBED = new MessageEmbed({
            author: ({ name: `${target.user.tag}`, iconURL: target.user.displayAvatarURL({ dynamic: true }) }),
            description: `<@${target.user.id}> **|** \`${target.user.id}\``,
            thumbnail: ({ url: target.user.displayAvatarURL({ dynamic: true }) }),
            fields: [
                {
                    name: "Registered",
                    value: `${time(Math.floor(target.user.createdTimestamp / 1000), { style: TimestampStyles.RelativeTime })}`,
                    inline: true
                },
                {
                    name: "Joined",
                    value: `${time(Math.floor(target.joinedTimestamp / 1000), { style: TimestampStyles.RelativeTime })}`,
                    inline: true
                }
            ]
        })

        msg.channel.send({ embeds: [EMBED] })

    }
}
#
TypeError: Cannot read properties of undefined (reading 'tag')
    at module.exports.run (D:\CLIENT\Client\src\Build\commands\Information\userinfo.js:49:36)
    at processTicksAndRejections (node:internal/process/task_queues:96:5) Promise {
  <rejected> TypeError: Cannot read properties of undefined (reading 'tag')
      at module.exports.run (D:\CLIENT\Client\src\Build\commands\Information\userinfo.js:49:36)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
}
stoic gale
#

Ok, add console.log(target) before const EMBED

#

my assumption here is that msg.member is a partial, and doesn't contain any user information/the information is limited

raven glen
#

Oh well just returns a log of all the guild members

stoic gale
# raven glen

Oh, that makes sense, <Guild>.members.fetch() returns all members if you pass undefined into it

#

If a UserResolvable, the user to fetch. If undefined, fetches all members. If a query, it limits the results to users with similar usernames.

#

Basically, since args[0] is undefined, it will return all members, so the fix is as I put originally, switch to using an if to check first

let target = msg.member
if (msg.mentions.members.last())) {
  target = msg.mentions.members.last()
} else if (args[0]) {
  target = await msg.guild.members.fetch(args[0])
}