File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -77,4 +77,20 @@ export class MonetizationAPI {
77
77
) {
78
78
await this . rest . delete ( Routes . entitlement ( applicationId , entitlementId ) , { signal } ) ;
79
79
}
80
+
81
+ /**
82
+ * Marks a given entitlement for the user as consumed. Only available for One-Time Purchase consumable SKUs.
83
+ *
84
+ * @see {@link https://discord.com/developers/docs/monetization/entitlements#consume-an-entitlement }
85
+ * @param applicationId - The application id to consume the entitlement for
86
+ * @param entitlementId - The entitlement id to consume
87
+ * @param options - The options for consuming the entitlement
88
+ */
89
+ public async consumeEntitlement (
90
+ applicationId : Snowflake ,
91
+ entitlementId : Snowflake ,
92
+ { signal } : Pick < RequestData , 'signal' > = { } ,
93
+ ) {
94
+ await this . rest . post ( Routes . consumeEntitlement ( applicationId , entitlementId ) , { signal } ) ;
95
+ }
80
96
}
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
+ const { Routes } = require ( 'discord-api-types/v10' ) ;
3
4
const Base = require ( './Base' ) ;
4
5
5
6
/**
@@ -91,6 +92,16 @@ class Entitlement extends Base {
91
92
} else {
92
93
this . endsTimestamp ??= null ;
93
94
}
95
+
96
+ if ( 'consumed' in data ) {
97
+ /**
98
+ * Whether this entitlement has been consumed
99
+ * @type {boolean }
100
+ */
101
+ this . consumed = data . consumed ;
102
+ } else {
103
+ this . consumed ??= false ;
104
+ }
94
105
}
95
106
96
107
/**
@@ -159,6 +170,15 @@ class Entitlement extends Base {
159
170
fetchUser ( ) {
160
171
return this . client . users . fetch ( this . userId ) ;
161
172
}
173
+
174
+ /**
175
+ * Marks this entitlement as consumed
176
+ * <info>Only available for One-Time Purchase consumable SKUs.</info>
177
+ * @returns {Promise<void> }
178
+ */
179
+ async consume ( ) {
180
+ await this . client . rest . post ( Routes . consumeEntitlement ( this . applicationId , this . id ) ) ;
181
+ }
162
182
}
163
183
164
184
exports . Entitlement = Entitlement ;
Original file line number Diff line number Diff line change @@ -1343,12 +1343,14 @@ export class Entitlement extends Base {
1343
1343
public guildId : Snowflake | null ;
1344
1344
public applicationId : Snowflake ;
1345
1345
public type : EntitlementType ;
1346
+ public consumed : boolean ;
1346
1347
public deleted : boolean ;
1347
1348
public startsTimestamp : number | null ;
1348
1349
public endsTimestamp : number | null ;
1349
1350
public get guild ( ) : Guild | null ;
1350
1351
public get startsAt ( ) : Date | null ;
1351
1352
public get endsAt ( ) : Date | null ;
1353
+ public consume ( ) : Promise < void > ;
1352
1354
public fetchUser ( ) : Promise < User > ;
1353
1355
public isActive ( ) : boolean ;
1354
1356
public isTest ( ) : this is this & {
You can’t perform that action at this time.
0 commit comments