#guild.ownerId returning undefined
1 messages · Page 1 of 1 (latest)
<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
Ah
so fetchOwner works, except I am getting back a Collection, rather than a GuildMember
Collection?
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
},
...
Could you try doing guild.fetchOwner().then(owner => {console.log(owner)})
that is essentially what I am doing, but using async/await
no worries
it shouldn't return a collection. the docs indicated a GuildMemebr
Yeah
Im not sure if this will work but maybe <guild>.fetchOwner() and <guild>.ownerId?
looking at the code it may be because ownerId is undefined:
fetchOwner(options) {
return this.members.fetch({ ...options, user: this.ownerId });
}
Shit Im having deja vu within deja vu
how do you mean?
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
ah ok 🙂
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 });
}
Ah
so it looks like the Intents.FLAGS.GUILDS is needed
You dont have that?
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
I have opened a ticket. will see what the team feels: https://github.com/discordjs/discord.js/issues/7574
Alright
Its a shame this is not described clearly in the docs