From c767221869c7b4648cd6739bf270559152b28e76 Mon Sep 17 00:00:00 2001 From: PakkoGraphic <41129374+pakkographic@users.noreply.github.com> Date: Mon, 21 Nov 2022 18:45:04 +0100 Subject: [PATCH] Deprecating `ForumThreadComment.createdBy` & more. * Deprecated `ForumThreadComment.createdBy` in favor of `ForumThreadComment.ownerID` * Added `ForumThreadComment.owner` --- lib/structures/ForumThreadComment.ts | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/structures/ForumThreadComment.ts b/lib/structures/ForumThreadComment.ts index 0273d808..d21dc9e6 100644 --- a/lib/structures/ForumThreadComment.ts +++ b/lib/structures/ForumThreadComment.ts @@ -1,6 +1,8 @@ /** @module ForumThreadComment */ import { Client } from "./Client"; import { Base } from "./Base"; +import { Member } from "./Member"; +import { User } from "./User"; import { APIForumTopicComment } from "../Constants"; import { CreateForumCommentOptions, EditForumCommentOptions, ConstructorForumThreadOptions } from "../types/forumThreadComment"; @@ -14,8 +16,8 @@ export class ForumThreadComment extends Base { updatedAt?: string; /** The ID of the forum thread */ threadID: number; - /** The ID of the user who created this forum thread comment (Note: If this event has createdByWebhookId present, this field will still be populated, but can be ignored. In this case, the value of this field will always be Ann6LewA) */ - createdBy: string; + /** The ID of the owner of this forum thread comment */ + ownerID: string; /** ID of the forum thread's server, if provided. */ guildID: string | null; /** ID of the forum channel containing this thread. */ @@ -28,10 +30,24 @@ export class ForumThreadComment extends Base { this.updatedAt = data.updatedAt; this.channelID = data.channelId; this.threadID = data.forumTopicId; - this.createdBy = data.createdBy; + this.ownerID = data.createdBy; this.guildID = options?.guildID ?? null; } + /** Retrieve the thread comment's owner, if cached. + * If there is no cached member or user, this will make a request which returns a Promise. + * If the request fails, this will throw an error or return you undefined as a value. + */ + get owner(): Member | User | Promise | undefined { + if (this.client.cache.members.get(this.ownerID) && this.ownerID){ + return this.client.cache.members.get(this.ownerID); + } else if (this.client.cache.users.get(this.ownerID) && this.ownerID){ + return this.client.cache.users.get(this.ownerID); + } else if (this.ownerID && this.guildID){ + return this.client.rest.guilds.getMember(this.guildID, this.ownerID); + } + } + /** Add a comment to the same forum thread as this comment. * @param options New comment's options. */