diff --git a/packages/core/__tests__/types.test.ts b/packages/core/__tests__/types.test.ts index 95f1ea7a04cc..11c086d4838f 100644 --- a/packages/core/__tests__/types.test.ts +++ b/packages/core/__tests__/types.test.ts @@ -131,4 +131,19 @@ describe('Interaction with_response overloads.', () => { }), ); }); + + test('Launch activity returns undefined.', () => { + assertType>(api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: false })); + assertType>(api.interactions.launchActivity(SNOWFLAKE, TOKEN)); + }); + + test('Launch activity returns RESTPostAPIInteractionCallbackWithResponseResult.', () => + assertType>( + api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: true }), + )); + + test('Launch activity returns either RESTPostAPIInteractionCallbackWithResponseResult or undefined.', () => + assertType>( + api.interactions.launchActivity(SNOWFLAKE, TOKEN, { with_response: boolValue }), + )); }); diff --git a/packages/core/src/api/interactions.ts b/packages/core/src/api/interactions.ts index 82aac602bb95..f159f2648210 100644 --- a/packages/core/src/api/interactions.ts +++ b/packages/core/src/api/interactions.ts @@ -525,4 +525,70 @@ export class InteractionsAPI { return with_response ? response : undefined; } + + /** + * Launches an activity and returns an interaction callback object + * + * @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 body - The callback data for launching the activity + * @param options - The options for launching the activity + */ + public async launchActivity( + interactionId: Snowflake, + interactionToken: string, + body: RESTPostAPIInteractionCallbackQuery & { with_response: true }, + options?: Pick, + ): Promise; + + /** + * Launches an activity + * + * @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 body - The callback data for launching the activity + * @param options - The options for launching the activity + */ + public async launchActivity( + interactionId: Snowflake, + interactionToken: string, + body?: RESTPostAPIInteractionCallbackQuery & { with_response?: false }, + options?: Pick, + ): Promise; + + /** + * Launches an activity + * + * @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 body - The callback data for launching the activity + * @param options - The options for launching the activity + */ + public async launchActivity( + interactionId: Snowflake, + interactionToken: string, + body?: RESTPostAPIInteractionCallbackQuery, + options?: Pick, + ): Promise; + + public async launchActivity( + interactionId: Snowflake, + interactionToken: string, + { with_response }: RESTPostAPIInteractionCallbackQuery = {}, + { signal }: Pick = {}, + ) { + const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { + query: makeURLSearchParams({ with_response }), + auth: false, + body: { + type: InteractionResponseType.LaunchActivity, + }, + signal, + }); + + return with_response ? response : undefined; + } }