Skip to content

Commit

Permalink
feat(interactions): add sendPremiumRequired()
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidx committed Oct 23, 2023
1 parent 61e3f22 commit 73f126e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
40 changes: 32 additions & 8 deletions packages/core/src/api/interactions.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down Expand Up @@ -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,
});
}
}
2 changes: 0 additions & 2 deletions packages/discord.js/test/monetization.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ client.on(Events.InteractionCreate, async interaction => {
console.log('interaction.entitlements', interaction.entitlements);

if (interaction.commandName === 'test') {
await interaction.deferReply();

await interaction.sendPremiumRequired();
}
});
Expand Down

0 comments on commit 73f126e

Please sign in to comment.