Skip to content

Commit 73f126e

Browse files
committed
feat(interactions): add sendPremiumRequired()
1 parent 61e3f22 commit 73f126e

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

packages/core/src/api/interactions.ts

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
/* eslint-disable jsdoc/check-param-names */
22

33
import type { RawFile, RequestData, REST } from '@discordjs/rest';
4-
import { InteractionResponseType, Routes } from 'discord-api-types/v10';
5-
import type {
6-
APICommandAutocompleteInteractionResponseCallbackData,
7-
APIInteractionResponseCallbackData,
8-
APIModalInteractionResponseCallbackData,
9-
RESTGetAPIWebhookWithTokenMessageResult,
10-
Snowflake,
11-
APIInteractionResponseDeferredChannelMessageWithSource,
4+
import {
5+
InteractionResponseType,
6+
Routes,
7+
type APICommandAutocompleteInteractionResponseCallbackData,
8+
type APIInteractionResponseCallbackData,
9+
type APIInteractionResponseDeferredChannelMessageWithSource,
10+
type APIModalInteractionResponseCallbackData,
11+
type APIPremiumRequiredInteractionResponse,
12+
type RESTGetAPIWebhookWithTokenMessageResult,
13+
type Snowflake,
1214
} from 'discord-api-types/v10';
1315
import type { WebhooksAPI } from './webhook.js';
1416

@@ -248,4 +250,26 @@ export class InteractionsAPI {
248250
signal,
249251
});
250252
}
253+
254+
/**
255+
* Sends a premium required response to an interaction
256+
*
257+
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response}
258+
* @param interactionId - The id of the interaction
259+
* @param interactionToken - The token of the interaction
260+
* @param options - The options for sending the premium required response
261+
*/
262+
public async sendPremiumRequired(
263+
interactionId: Snowflake,
264+
interactionToken: string,
265+
{ signal }: Pick<RequestData, 'signal'> = {},
266+
) {
267+
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
268+
auth: false,
269+
body: {
270+
type: InteractionResponseType.PremiumRequired,
271+
} satisfies APIPremiumRequiredInteractionResponse,
272+
signal,
273+
});
274+
}
251275
}

packages/discord.js/test/monetization.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ client.on(Events.InteractionCreate, async interaction => {
3535
console.log('interaction.entitlements', interaction.entitlements);
3636

3737
if (interaction.commandName === 'test') {
38-
await interaction.deferReply();
39-
4038
await interaction.sendPremiumRequired();
4139
}
4240
});

0 commit comments

Comments
 (0)