#guild.ownerId returning undefined

1 messages · Page 1 of 1 (latest)

unique pumice
#

<guild> is an valid guild object correct?

#

Most likely, the owner of the guild is not fetched. You can fetch them using js <guild>.fetchOwner(options)
https://discord.js.org/#/docs/discord.js/stable/class/Guild?scrollTo=fetchOwner

mellow walrus
#

Trying via guildMember.guild.ownerId

#

let me check at the top direct call

unique pumice
#

Ah

mellow walrus
#

so fetchOwner works, except I am getting back a Collection, rather than a GuildMember

unique pumice
#

Collection?

mellow walrus
#

so this is the code:

const guild = await DiscordService.getGuild();
console.log('xxxxoooo', await guild.fetchOwner());
#

for example (truncated):

#
xxxxoooo Collection(11) [Map] {
  '109825136563081216' => GuildMember {
    guild: Guild {
      id: '577355180228739072',
      name: undefined,
      icon: undefined,
      features: undefined,
      commands: [GuildApplicationCommandManager],
      members: [GuildMemberManager],
      channels: [GuildChannelManager],
      bans: [GuildBanManager],
      roles: [RoleManager],
      presences: PresenceManager {},
      voiceStates: [VoiceStateManager],
      stageInstances: [StageInstanceManager],
      invites: [GuildInviteManager],
      scheduledEvents: [GuildScheduledEventManager],
      available: false,
      shardId: 0
    },
    joinedTimestamp: 1642542528653,
    premiumSinceTimestamp: null,
    nickname: null,
    pending: false,
    communicationDisabledUntilTimestamp: null,
    _roles: [ '932721509905084436' ],
    user: User {
      id: '109825136563081216',
      bot: false,
      system: false,
      flags: null,
      username: 'Merikato',
      discriminator: '0001',
      avatar: 'a_8728b8f388872ec51d4e7890b49e3aec',
      banner: undefined,
      accentColor: undefined
    },
    avatar: null
  },
  ...
unique pumice
mellow walrus
#

that is essentially what I am doing, but using async/await

unique pumice
#

ah

#

sorry

mellow walrus
#

no worries

unique pumice
#

It shouldnt return that large of a collection

#

or maybe it should

mellow walrus
#

it shouldn't return a collection. the docs indicated a GuildMemebr

unique pumice
#

Yeah

#

Im not sure if this will work but maybe <guild>.fetchOwner() and <guild>.ownerId?

mellow walrus
#

looking at the code it may be because ownerId is undefined:

#

fetchOwner(options) {
return this.members.fetch({ ...options, user: this.ownerId });
}

unique pumice
#

Shit Im having deja vu within deja vu

mellow walrus
#

how do you mean?

unique pumice
#

I feel like this has happened before but I dont do support here so it couldnt have

#

within the deju vu, i remember having deja vu

mellow walrus
#

ah ok 🙂

unique pumice
#

This whole thing is weird

#

What's in <Collection>[1]?

mellow walrus
#

its the guild members

#

there is a bug in the the discord code

#

since if guild.owerId is undefined, this won't filter:

#
fetchOwner(options) {
    return this.members.fetch({ ...options, user: this.ownerId });
  }
unique pumice
#

Ah

mellow walrus
#

so it looks like the Intents.FLAGS.GUILDS is needed

unique pumice
#

You dont have that?

mellow walrus
#

but still think the library should help with a better exception

#

no

#

Tempted to suggest improved code would be:

fetchOwner(options) {
    if (!this.ownerId) {
       throw new MissingIntent('Guilds intent is required');
    }
    return this.members.fetch({ ...options, user: this.ownerId });
}
#

though not sure whether that fits with the vision of the dev team

unique pumice
#

Mhm

#

github

#

did that work?

mellow walrus
unique pumice
#

Alright

mellow walrus
#

Its a shame this is not described clearly in the docs