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: Add role subscription data #9025

Merged
merged 9 commits into from
Feb 17, 2023
25 changes: 25 additions & 0 deletions packages/discord.js/src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* <info>This is present on {@link MessageType.RoleSubscriptionPurchase} messages.</info>
* @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) {
/**
Expand Down
8 changes: 8 additions & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1921,6 +1921,7 @@ export class Message<InGuild extends boolean = boolean> extends Base {
public reactions: ReactionManager;
public stickers: Collection<Snowflake, Sticker>;
public position: number | null;
public roleSubscriptionData: RoleSubscriptionData | null;
public system: boolean;
public get thread(): AnyThreadChannel | null;
public tts: boolean;
Expand Down Expand Up @@ -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;
Expand Down