diff --git a/packages/discord.js/src/managers/EntitlementManager.js b/packages/discord.js/src/managers/EntitlementManager.js index a392b05b93ca..1456d3719acb 100644 --- a/packages/discord.js/src/managers/EntitlementManager.js +++ b/packages/discord.js/src/managers/EntitlementManager.js @@ -124,6 +124,16 @@ class EntitlementManager extends CachedManager { await this.client.rest.delete(Routes.entitlement(this.client.application.id, resolved)); } + + /** + * Marks an entitlement as consumed + * Only available for One-Time Purchase consumable SKUs. + * @param {Snowflake} entitlementId The id of the entitlement to consume + * @returns {Promise} + */ + async consume(entitlementId) { + await this.client.rest.post(Routes.consumeEntitlement(this.client.application.id, entitlementId)); + } } exports.EntitlementManager = EntitlementManager; diff --git a/packages/discord.js/src/structures/Entitlement.js b/packages/discord.js/src/structures/Entitlement.js index c10fe7022d0d..115873438cf0 100644 --- a/packages/discord.js/src/structures/Entitlement.js +++ b/packages/discord.js/src/structures/Entitlement.js @@ -1,6 +1,5 @@ 'use strict'; -const { Routes } = require('discord-api-types/v10'); const Base = require('./Base'); /** @@ -177,7 +176,7 @@ class Entitlement extends Base { * @returns {Promise} */ async consume() { - await this.client.rest.post(Routes.consumeEntitlement(this.applicationId, this.id)); + await this.client.application.entitlements.consume(this.id); } } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 5168c674de09..e33c250b4e9b 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -4143,6 +4143,7 @@ export class EntitlementManager extends CachedManager>; public createTest(options: GuildEntitlementCreateOptions | UserEntitlementCreateOptions): Promise; public deleteTest(entitlement: EntitlementResolvable): Promise; + public consume(entitlementId: Snowflake): Promise; } export interface FetchGuildApplicationCommandFetchOptions extends Omit {} diff --git a/packages/discord.js/typings/index.test-d.ts b/packages/discord.js/typings/index.test-d.ts index e3616c9f8232..ddf86077235a 100644 --- a/packages/discord.js/typings/index.test-d.ts +++ b/packages/discord.js/typings/index.test-d.ts @@ -2494,6 +2494,8 @@ declare const sku: SKU; await application.entitlements.deleteTest(entitlement); + await application.entitlements.consume(snowflake); + expectType(entitlement.isActive()); if (entitlement.isUserSubscription()) {