Skip to content

Commit

Permalink
feat: move logic to EntitlementManager
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidx committed May 1, 2024
1 parent 0de148d commit b51b2dd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions packages/discord.js/src/managers/EntitlementManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <info>Only available for One-Time Purchase consumable SKUs.</info>
* @param {Snowflake} entitlementId The id of the entitlement to consume
* @returns {Promise<void>}
*/
async consume(entitlementId) {
await this.client.rest.post(Routes.consumeEntitlement(this.client.application.id, entitlementId));
}
}

exports.EntitlementManager = EntitlementManager;
3 changes: 1 addition & 2 deletions packages/discord.js/src/structures/Entitlement.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';

const { Routes } = require('discord-api-types/v10');
const Base = require('./Base');

/**
Expand Down Expand Up @@ -177,7 +176,7 @@ class Entitlement extends Base {
* @returns {Promise<void>}
*/
async consume() {
await this.client.rest.post(Routes.consumeEntitlement(this.applicationId, this.id));
await this.client.application.entitlements.consume(this.id);
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4143,6 +4143,7 @@ export class EntitlementManager extends CachedManager<Snowflake, Entitlement, En
public fetch(options?: FetchEntitlementsOptions): Promise<Collection<Snowflake, Entitlement>>;
public createTest(options: GuildEntitlementCreateOptions | UserEntitlementCreateOptions): Promise<Entitlement>;
public deleteTest(entitlement: EntitlementResolvable): Promise<void>;
public consume(entitlementId: Snowflake): Promise<void>;
}

export interface FetchGuildApplicationCommandFetchOptions extends Omit<FetchApplicationCommandOptions, 'guildId'> {}
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2494,6 +2494,8 @@ declare const sku: SKU;

await application.entitlements.deleteTest(entitlement);

await application.entitlements.consume(snowflake);

expectType<boolean>(entitlement.isActive());

if (entitlement.isUserSubscription()) {
Expand Down

0 comments on commit b51b2dd

Please sign in to comment.