Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Guild): replace owner with fetchOwner #5480

Merged
merged 2 commits into from Apr 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 13 additions & 10 deletions src/structures/Guild.js
Expand Up @@ -526,17 +526,20 @@ class Guild extends Base {
}

/**
* The owner of the guild
* @type {?GuildMember}
* @readonly
* Options used to fetch the owner of guild.
* @typedef {Object} FetchOwnerOptions
* @property {boolean} [cache=true] Whether or not to cache the fetched member
* @property {boolean} [force=false] Whether to skip the cache check and request the API
*/
get owner() {
return (
this.members.cache.get(this.ownerID) ||
(this.client.options.partials.includes(PartialTypes.GUILD_MEMBER)
? this.members.add({ user: { id: this.ownerID } }, true)
: null)
);

/**
* Fetches the owner of the guild
* If the member object isn't needed, use {@link Guild#ownerID} instead
* @param {FetchOwnerOptions} [options] The options for fetching the member
* @returns {Promise<GuildMember>}
*/
fetchOwner(options) {
return this.members.fetch({ ...options, user: this.ownerID });
}

/**
Expand Down
4 changes: 3 additions & 1 deletion typings/index.d.ts
Expand Up @@ -619,7 +619,6 @@ declare module 'discord.js' {
public mfaLevel: number;
public name: string;
public readonly nameAcronym: string;
public readonly owner: GuildMember | null;
public ownerID: Snowflake;
public readonly partnered: boolean;
public preferredLocale: string;
Expand Down Expand Up @@ -660,6 +659,7 @@ declare module 'discord.js' {
public fetchBans(): Promise<Collection<Snowflake, { user: User; reason: string }>>;
public fetchIntegrations(): Promise<Collection<string, Integration>>;
public fetchInvites(): Promise<Collection<string, Invite>>;
public fetchOwner(options?: FetchOwnerOptions): Promise<GuildMember>;
public fetchPreview(): Promise<GuildPreview>;
public fetchTemplates(): Promise<Collection<GuildTemplate['code'], GuildTemplate>>;
public fetchVanityData(): Promise<Vanity>;
Expand Down Expand Up @@ -2655,6 +2655,8 @@ declare module 'discord.js' {
name?: string;
}

type FetchOwnerOptions = Omit<FetchMemberOptions, 'user'>;

type GuildAuditLogsAction = keyof GuildAuditLogsActions;

interface GuildAuditLogsActions {
Expand Down