Home > Enterprise >  User gives back undefined, but gives back information when I console log it
User gives back undefined, but gives back information when I console log it

Time:10-31

I'm fetching a user from a channel topic, because I'm working on a ticket system, but whenever I fetch that user by its ID, which is in the channel topic I cannot call it as it gives back undefined. However, when I console.log(member); it does provide me all the information which is correct. I really hope someone has an answer!

My code to fetch the user: const member = await interaction.guild.members.fetch(interaction.channel.topic);

Whenever I request member in lets say my embed it will give back undefined.

Member used in embed:

const transcript = new MessageEmbed()
                .setColor(0xAE0808)
                .setTitle("Test")
                .setDescription(`Transcript of ${interaction.channel.name}`)
                .setFooter("Test")
                .addField("id", `${member.id}`)
                .addField("username", `${member.username}`)
                .addField("discriminator", `${member.discriminator}`)
                .setThumbnail(member.avatarURL)
            await ticketlogs.send({
                embeds: [transcript]
            });

Embed return:

Example

Console log when I request member:

GuildMember {
  guild: <ref *1> Guild {
    id: '859420793892896798',
    name: 'Discord Dev Server',
    icon: '167da12983da8af5f8f7aadd0b897970',
    features: [],
    commands: GuildApplicationCommandManager {
      permissions: [ApplicationCommandPermissionsManager],
      guild: [Circular *1]
    },
    members: GuildMemberManager { guild: [Circular *1] },
    channels: GuildChannelManager { guild: [Circular *1] },
    bans: GuildBanManager { guild: [Circular *1] },
    roles: RoleManager { guild: [Circular *1] },
    presences: PresenceManager {},
    voiceStates: VoiceStateManager { guild: [Circular *1] },
    stageInstances: StageInstanceManager { guild: [Circular *1] },
    invites: GuildInviteManager { guild: [Circular *1] },
    deleted: false,
    available: true,
    shardId: 0,
    splash: null,
    banner: null,
    description: null,
    verificationLevel: 'MEDIUM',
    vanityURLCode: null,
    nsfwLevel: 'DEFAULT',
    discoverySplash: null,
    memberCount: 14,
    large: false,
    applicationId: null,
    afkTimeout: 300,
    afkChannelId: null,
    systemChannelId: null,
    premiumTier: 'NONE',
    premiumSubscriptionCount: 0,
    explicitContentFilter: 'DISABLED',
    mfaLevel: 'NONE',
    joinedTimestamp: 1631522277559,
    defaultMessageNotifications: 'ONLY_MENTIONS',
    systemChannelFlags: SystemChannelFlags { bitfield: 0 },
    maximumMembers: 250000,
    maximumPresences: null,
    approximateMemberCount: null,
    approximatePresenceCount: null,
    vanityURLUses: null,
    rulesChannelId: null,
    publicUpdatesChannelId: null,
    preferredLocale: 'en-US',
    ownerId: '574958028651233281',
    emojis: GuildEmojiManager { guild: [Circular *1] },
    stickers: GuildStickerManager { guild: [Circular *1] }
  },
  joinedTimestamp: 1624972284534,
  premiumSinceTimestamp: null,
  deleted: false,
  nickname: null,
  pending: false,
  _roles: [ '859444413625008169', '872068996936114218' ],
  user: User {
    id: '574958028651233281',
    bot: false,
    system: false,
    flags: UserFlags { bitfield: 128 },
    username: 'Bram',
    discriminator: '2698',
    avatar: '61791bfd3f12e81e75708d03dd2cc5fa'
  }
}

CodePudding user response:

Your code to fetch the user is correct, however, you try to access properties that doesn't exist.

Try using member.user.username and member.user.discriminator instead ;)

  • Related