From 1ba22f4c9e4173f8866339d3eadb2939d4b32034 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 17 Feb 2023 19:47:08 +0000 Subject: [PATCH] feat: Add role subscription data (#9025) * feat: add role subscription data * docs: specify message type * types: use interface * docs: add word --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- packages/discord.js/src/structures/Message.js | 25 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 8 ++++++ 2 files changed, 33 insertions(+) diff --git a/packages/discord.js/src/structures/Message.js b/packages/discord.js/src/structures/Message.js index dd5a4b6ff..9a1df99d7 100644 --- a/packages/discord.js/src/structures/Message.js +++ b/packages/discord.js/src/structures/Message.js @@ -198,6 +198,31 @@ class Message extends Base { this.position ??= null; } + if ('role_subscription_data' in data) { + /** + * Role subscription data found on {@link MessageType.RoleSubscriptionPurchase} messages. + * @typedef {Object} RoleSubscriptionData + * @property {Snowflake} roleSubscriptionListingId The id of the SKU and listing the user is subscribed to + * @property {string} tierName The name of the tier the user is subscribed to + * @property {number} totalMonthsSubscribed The total number of months the user has been subscribed for + * @property {boolean} isRenewal Whether this notification is a renewal + */ + + /** + * The data of the role subscription purchase or renewal. + * This is present on {@link MessageType.RoleSubscriptionPurchase} messages. + * @type {?RoleSubscriptionData} + */ + this.roleSubscriptionData = { + roleSubscriptionListingId: data.role_subscription_data.role_subscription_listing_id, + tierName: data.role_subscription_data.tier_name, + totalMonthsSubscribed: data.role_subscription_data.total_months_subscribed, + isRenewal: data.role_subscription_data.is_renewal, + }; + } else { + this.roleSubscriptionData ??= null; + } + // Discord sends null if the message has not been edited if (data.edited_timestamp) { /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 285075107..fd6777177 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1921,6 +1921,7 @@ export class Message extends Base { public reactions: ReactionManager; public stickers: Collection; public position: number | null; + public roleSubscriptionData: RoleSubscriptionData | null; public system: boolean; public get thread(): AnyThreadChannel | null; public tts: boolean; @@ -6016,6 +6017,13 @@ export interface RolePosition { export type RoleResolvable = Role | Snowflake; +export interface RoleSubscriptionData { + roleSubscriptionListingId: Snowflake; + tierName: string; + totalMonthsSubscribed: number; + isRenewal: boolean; +} + export interface RoleTagData { botId?: Snowflake; integrationId?: Snowflake;