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(ThreadChannel): add fetchOwner() method #6207

Merged
merged 7 commits into from Jul 31, 2021
Merged
2 changes: 1 addition & 1 deletion src/structures/Guild.js
Expand Up @@ -458,7 +458,7 @@ class Guild extends AnonymousGuild {
}

/**
* Options used to fetch the owner of guild.
* Options used to fetch the owner of a guild or a thread.
* @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
Expand Down
16 changes: 16 additions & 0 deletions src/structures/ThreadChannel.js
Expand Up @@ -234,6 +234,22 @@ class ThreadChannel extends Channel {
return this.parent?.permissionsFor(memberOrRole) ?? null;
}

/**
* Fetches the owner of this thread
* @param {FetchOwnerOptions} [options] The options for fetching the member
ImRodry marked this conversation as resolved.
Show resolved Hide resolved
* @returns {Promise<ThreadMember>}
ImRodry marked this conversation as resolved.
Show resolved Hide resolved
*/
async fetchOwner({ cache = true, force = false } = {}) {
if (!force) {
const existing = this.members.cache.get(this.ownerId);
if (existing) return existing;
}

// We cannot fetch a single thread member, as of this commit's date, Discord API responds with 405
const members = await this.members.fetch(cache);
return members.get(this.ownerId) ?? null;
}

/**
* The options used to edit a thread channel
* @typedef {Object} ThreadEditData
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -1699,6 +1699,7 @@ export class ThreadChannel extends TextBasedChannel(Channel) {
public leave(): Promise<ThreadChannel>;
public permissionsFor(memberOrRole: GuildMember | Role): Readonly<Permissions>;
public permissionsFor(memberOrRole: GuildMemberResolvable | RoleResolvable): Readonly<Permissions> | null;
public fetchOwner(options?: FetchOwnerOptions): Promise<ThreadMember | null>;
public setArchived(archived?: boolean, reason?: string): Promise<ThreadChannel>;
public setAutoArchiveDuration(
autoArchiveDuration: ThreadAutoArchiveDuration,
Expand Down