mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-12 09:33:32 +01:00
feat: premium application subscriptions (#9907)
* feat: premium application subscriptions * types: readonly array Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * fix: requested changes Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> * fix: core client types --------- Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
@@ -5,6 +5,7 @@ import { ChannelsAPI } from './channel.js';
|
||||
import { GuildsAPI } from './guild.js';
|
||||
import { InteractionsAPI } from './interactions.js';
|
||||
import { InvitesAPI } from './invite.js';
|
||||
import { MonetizationAPI } from './monetization.js';
|
||||
import { OAuth2API } from './oauth2.js';
|
||||
import { RoleConnectionsAPI } from './roleConnections.js';
|
||||
import { StageInstancesAPI } from './stageInstances.js';
|
||||
@@ -20,6 +21,7 @@ export * from './channel.js';
|
||||
export * from './guild.js';
|
||||
export * from './interactions.js';
|
||||
export * from './invite.js';
|
||||
export * from './monetization.js';
|
||||
export * from './oauth2.js';
|
||||
export * from './roleConnections.js';
|
||||
export * from './stageInstances.js';
|
||||
@@ -42,6 +44,8 @@ export class API {
|
||||
|
||||
public readonly invites: InvitesAPI;
|
||||
|
||||
public readonly monetization: MonetizationAPI;
|
||||
|
||||
public readonly oauth2: OAuth2API;
|
||||
|
||||
public readonly roleConnections: RoleConnectionsAPI;
|
||||
@@ -64,6 +68,7 @@ export class API {
|
||||
this.channels = new ChannelsAPI(rest);
|
||||
this.guilds = new GuildsAPI(rest);
|
||||
this.invites = new InvitesAPI(rest);
|
||||
this.monetization = new MonetizationAPI(rest);
|
||||
this.roleConnections = new RoleConnectionsAPI(rest);
|
||||
this.oauth2 = new OAuth2API(rest);
|
||||
this.stageInstances = new StageInstancesAPI(rest);
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import type { RawFile, RequestData, REST } from '@discordjs/rest';
|
||||
import { InteractionResponseType, Routes } from 'discord-api-types/v10';
|
||||
import type {
|
||||
APICommandAutocompleteInteractionResponseCallbackData,
|
||||
APIInteractionResponseCallbackData,
|
||||
APIModalInteractionResponseCallbackData,
|
||||
RESTGetAPIWebhookWithTokenMessageResult,
|
||||
Snowflake,
|
||||
APIInteractionResponseDeferredChannelMessageWithSource,
|
||||
import {
|
||||
InteractionResponseType,
|
||||
Routes,
|
||||
type APICommandAutocompleteInteractionResponseCallbackData,
|
||||
type APIInteractionResponseCallbackData,
|
||||
type APIInteractionResponseDeferredChannelMessageWithSource,
|
||||
type APIModalInteractionResponseCallbackData,
|
||||
type APIPremiumRequiredInteractionResponse,
|
||||
type RESTGetAPIWebhookWithTokenMessageResult,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
import type { WebhooksAPI } from './webhook.js';
|
||||
|
||||
@@ -248,4 +250,26 @@ export class InteractionsAPI {
|
||||
signal,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sends a premium required response to an interaction
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response}
|
||||
* @param interactionId - The id of the interaction
|
||||
* @param interactionToken - The token of the interaction
|
||||
* @param options - The options for sending the premium required response
|
||||
*/
|
||||
public async sendPremiumRequired(
|
||||
interactionId: Snowflake,
|
||||
interactionToken: string,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
) {
|
||||
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
|
||||
auth: false,
|
||||
body: {
|
||||
type: InteractionResponseType.PremiumRequired,
|
||||
} satisfies APIPremiumRequiredInteractionResponse,
|
||||
signal,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
80
packages/core/src/api/monetization.ts
Normal file
80
packages/core/src/api/monetization.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
/* eslint-disable jsdoc/check-param-names */
|
||||
|
||||
import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
|
||||
import {
|
||||
Routes,
|
||||
type RESTGetAPIEntitlementsQuery,
|
||||
type RESTGetAPIEntitlementsResult,
|
||||
type RESTGetAPISKUsResult,
|
||||
type RESTPostAPIEntitlementBody,
|
||||
type RESTPostAPIEntitlementResult,
|
||||
type Snowflake,
|
||||
} from 'discord-api-types/v10';
|
||||
|
||||
export class MonetizationAPI {
|
||||
public constructor(private readonly rest: REST) {}
|
||||
|
||||
/**
|
||||
* Fetches the SKUs for an application.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/monetization/skus#list-skus}
|
||||
* @param options - The options for fetching the SKUs.
|
||||
*/
|
||||
public async getSKUs(applicationId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
|
||||
return this.rest.get(Routes.skus(applicationId), { signal }) as Promise<RESTGetAPISKUsResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the entitlements for an application.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/monetization/entitlements#list-entitlements}
|
||||
* @param applicationId - The application id to fetch entitlements for
|
||||
* @param query - The query options for fetching entitlements
|
||||
* @param options - The options for fetching entitlements
|
||||
*/
|
||||
public async getEntitlements(
|
||||
applicationId: Snowflake,
|
||||
query: RESTGetAPIEntitlementsQuery,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
) {
|
||||
return this.rest.get(Routes.entitlements(applicationId), {
|
||||
signal,
|
||||
query: makeURLSearchParams(query),
|
||||
}) as Promise<RESTGetAPIEntitlementsResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a test entitlement for an application's SKU.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/monetization/entitlements#create-test-entitlement}
|
||||
* @param applicationId - The application id to create the entitlement for
|
||||
* @param body - The data for creating the entitlement
|
||||
* @param options - The options for creating the entitlement
|
||||
*/
|
||||
public async createTestEntitlement(
|
||||
applicationId: Snowflake,
|
||||
body: RESTPostAPIEntitlementBody,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
) {
|
||||
return this.rest.post(Routes.entitlements(applicationId), {
|
||||
body,
|
||||
signal,
|
||||
}) as Promise<RESTPostAPIEntitlementResult>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a test entitlement for an application's SKU.
|
||||
*
|
||||
* @see {@link https://discord.com/developers/docs/monetization/entitlements#delete-test-entitlement}
|
||||
* @param applicationId - The application id to delete the entitlement for
|
||||
* @param entitlementId - The entitlement id to delete
|
||||
* @param options - The options for deleting the entitlement
|
||||
*/
|
||||
public async deleteTestEntitlement(
|
||||
applicationId: Snowflake,
|
||||
entitlementId: Snowflake,
|
||||
{ signal }: Pick<RequestData, 'signal'> = {},
|
||||
) {
|
||||
await this.rest.delete(Routes.entitlement(applicationId, entitlementId), { signal });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user