question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

guild.fetchOwner() is returning a collection of guild members

See original GitHub issue

Which package is this bug report for?

discord.js

Issue description

Using Discord 13.6.0 I am trying to get the id of the guild, is not working for me.

Trying guild.ownerId returns undefined, but I was then directed to try guild.fetchOwner(), but this returns a list of members of the guild instead of a GuildMember.

Looking at the Discord source code suggests that if guild.ownerId is undefined, this will return all the members of the guild:

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



### Code sample

```typescript
To get the guild:


  async getGuild (guildId?: string) {
    const client = await this.getClient();
    const guildResolvable = client.guilds.resolveId(guildId || this.guildId);

    const guild = client.guilds.resolve(guildResolvable);
    if (!guild) {
      throw new Error('Unable to access guild');
    }
    return guild;
  }


This returns a guild with `ownerId` being `undefined, but then calling `guild.fetchOwner()` returns a collection of form `Collection(11) [Map] { ... }`.

Package version

13.6.0

Node.js version

16.6.0

Operating system

macOS

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

No Partials

Which gateway intents are you subscribing to?

GuildMembers, GuildMessages

I have tested this issue on a development release

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ajmascommented, Feb 27, 2022

Yes, I just noticed through extra experimenting, though it wasn’t clear from the documentation:

https://discord.js.org/#/docs/discord.js/stable/class/Guild?scrollTo=fetchOwner

Also, would it be possible to have code provide clarity on this, such as:

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

Though, not sure if that fits with the API’s philosophy?

0reactions
monbreycommented, Feb 27, 2022

Although I don’t agree with this particular error message, I do think this method should reject if guild.ownerId isn’t defined. It’s designed to fetch a single GuildMember. If it cannot do so, it should reject.

The current behaviour where in an edge case it can return a Collection of GuildMembers is not the expected result and should be considered a bug.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get owner of a guild in discord.js v13? - Stack Overflow
fetchOwner() method on it, which returns us a promise with when fulfilled returns us the GuildMember object of the owner.
Read more >
is it possible to get guild owner tag in discord.js v13?
ownerId const owner = guild.members.cache.get(ownerId) ... guild.fetchOwner() returns a promise, you need to add await .
Read more >
Discord.js v13 Guild Owner name of multiple servers. - Reddit
guild.fetchOwner it only returns Undefined, as you can't use await in a forEach loop, thought the loop might be able to grab the...
Read more >
discord.js-codemod - npm
Discord.js codemod scripts.. Latest version: 1.0.1, last published: a year ago. Start using discord.js-codemod in your project by running ...
Read more >
Updating from v12 to v13 - discord.js Guide
The Guild#owner property has been removed as it was unreliable due to caching, replaced with Guild#fetchOwner . - console.log(guild.owner); + ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found