Skip to content

Commit 1a26479

Browse files
committed
entry point commands
discord/discord-api-docs#7106
1 parent dee089f commit 1a26479

File tree

8 files changed

+63
-17
lines changed

8 files changed

+63
-17
lines changed

lib/Constants.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,9 +1088,10 @@ export enum AuditLogActionTypes {
10881088
}
10891089

10901090
export enum ApplicationCommandTypes {
1091-
CHAT_INPUT = 1,
1092-
USER = 2,
1093-
MESSAGE = 3,
1091+
CHAT_INPUT = 1,
1092+
USER = 2,
1093+
MESSAGE = 3,
1094+
PRIMARY_ENTRY_POINT = 4,
10941095
}
10951096

10961097
export enum ApplicationCommandOptionTypes {
@@ -1123,6 +1124,12 @@ export enum InteractionResponseTypes {
11231124
MODAL = 9,
11241125
/** @deprecated */
11251126
PREMIUM_REQUIRED = 10,
1127+
LAUNCH_ACTIVITY = 12,
1128+
}
1129+
1130+
export enum EntryPointCommandHandlerTypes {
1131+
APP_HANDLER = 1,
1132+
DISCORD_LAUNCH_ACTIVITY = 2,
11261133
}
11271134

11281135
export enum Intents {

lib/routes/Applications.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import type {
3131
ApplicationEmoji,
3232
ApplicationEmojis,
3333
CreateApplicationEmojiOptions,
34+
CreatePrimaryEntryPointApplicationCommandOptions,
3435
EditApplicationEmojiOptions,
3536
EditApplicationOptions,
3637
RESTApplication,
@@ -67,6 +68,7 @@ export default class Applications {
6768
default_member_permissions: opt.defaultMemberPermissions,
6869
description_localizations: opt.descriptionLocalizations,
6970
dm_permission: opt.dmPermission,
71+
handler: (opt as unknown as CreatePrimaryEntryPointApplicationCommandOptions).handler,
7072
integration_types: opt.integrationTypes,
7173
name: opt.name,
7274
name_localizations: opt.nameLocalizations,
@@ -151,12 +153,13 @@ export default class Applications {
151153
json: {
152154
contexts: opt.contexts,
153155
default_member_permissions: opt.defaultMemberPermissions,
154-
description: opt.description,
155156
description_localizations: opt.descriptionLocalizations,
157+
description: opt.description,
156158
dm_permission: opt.dmPermission,
159+
handler: (opt as unknown as CreatePrimaryEntryPointApplicationCommandOptions).handler,
157160
integration_types: opt.integrationTypes,
158-
name: opt.name,
159161
name_localizations: opt.nameLocalizations,
162+
name: opt.name,
160163
nsfw: opt.nsfw,
161164
options: opt.options?.map(o => this._manager.client.util.optionToRaw(o)),
162165
type: opt.type

lib/routes/Interactions.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ export default class Interactions {
3636
async createInteractionResponse(interactionID: string, interactionToken: string, options: InteractionResponse): Promise<void> {
3737
let data: unknown;
3838
switch (options.type) {
39-
case InteractionResponseTypes.PONG: {
39+
case InteractionResponseTypes.PONG:
40+
case InteractionResponseTypes.PREMIUM_REQUIRED:
41+
case InteractionResponseTypes.LAUNCH_ACTIVITY: {
4042
break;
4143
}
4244
case InteractionResponseTypes.CHANNEL_MESSAGE_WITH_SOURCE:

lib/structures/ApplicationCommand.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import Permission from "./Permission";
44
import type Guild from "./Guild";
55
import type ClientApplication from "./ClientApplication";
66
import type Client from "../Client";
7-
import { ApplicationCommandTypes, type InteractionContextTypes, type ApplicationIntegrationTypes } from "../Constants";
7+
import { ApplicationCommandTypes, type InteractionContextTypes, type ApplicationIntegrationTypes, type EntryPointCommandHandlerTypes } from "../Constants";
88
import type {
99
ApplicationCommandOptionConversion,
1010
ApplicationCommandOptions,
@@ -38,6 +38,8 @@ export default class ApplicationCommand<T extends ApplicationCommandTypes = Appl
3838
dmPermission?: boolean;
3939
/** The id of the guild this command is in (guild commands only). */
4040
guildID: string | null;
41+
/** The handler of this command. Only valid for `PRIMARY_ENTRY_POINT` commands. */
42+
handler?: EntryPointCommandHandlerTypes;
4143
/** The installation contexts in which this command is available. */
4244
integrationTypes: Array<ApplicationIntegrationTypes>;
4345
/** The name of this command. */
@@ -65,6 +67,7 @@ export default class ApplicationCommand<T extends ApplicationCommandTypes = Appl
6567
this.descriptionLocalized = data.description_localized;
6668
this.dmPermission = data.dm_permission;
6769
this.guildID = data.guild_id ?? null;
70+
this.handler = data.handler;
6871
this.integrationTypes = data.integration_types;
6972
this.name = data.name;
7073
this.nameLocalizations = data.name_localizations;
@@ -147,6 +150,7 @@ export default class ApplicationCommand<T extends ApplicationCommandTypes = Appl
147150
descriptionLocalizations: this.descriptionLocalizations,
148151
dmPermission: this.dmPermission,
149152
guildID: this.guildID ?? undefined,
153+
handler: this.handler,
150154
integrationTypes: this.integrationTypes,
151155
name: this.name,
152156
nameLocalizations: this.nameLocalizations,

lib/structures/CommandInteraction.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,28 @@ export default class CommandInteraction<T extends AnyInteractionChannel | Uncach
290290
return this.data.type === ApplicationCommandTypes.MESSAGE;
291291
}
292292

293+
/** A type guard, checking if this command interaction is a {@link Constants~ApplicationCommandTypes.PRIMARY_ENTRY_POINT | Primary Entry Point} command. */
294+
isPrimaryEntryPointCommand(): this is CommandInteraction<T, ApplicationCommandTypes.PRIMARY_ENTRY_POINT> {
295+
return this.data.type === ApplicationCommandTypes.PRIMARY_ENTRY_POINT;
296+
}
297+
293298
/** A type guard, checking if this command interaction is a {@link Constants~ApplicationCommandTypes.USER | User} command. */
294299
isUserCommand(): this is CommandInteraction<T, ApplicationCommandTypes.USER> {
295300
return this.data.type === ApplicationCommandTypes.USER;
296301
}
297302

303+
/**
304+
* Launch the bot's activity. This is an initial response, and more than one initial response cannot be used.
305+
*/
306+
async launchActivity(): Promise<void> {
307+
if (this.acknowledged) {
308+
throw new TypeError("Interactions cannot have more than one initial response.");
309+
}
310+
311+
this.acknowledged = true;
312+
return this.client.rest.interactions.createInteractionResponse(this.id, this.token, { type: InteractionResponseTypes.LAUNCH_ACTIVITY });
313+
}
314+
298315
/**
299316
* Show a "premium required" response to the user. This is an initial response, and more than one initial response cannot be used.
300317
* @deprecated The {@link Constants~InteractionResponseTypes.PREMIUM_REQUIRED | PREMIUM_REQUIRED} interaction response type is now deprecated in favor of using {@link Types/Channels~PremiumButton | custom premium buttons}.
@@ -305,7 +322,7 @@ export default class CommandInteraction<T extends AnyInteractionChannel | Uncach
305322
}
306323

307324
this.acknowledged = true;
308-
return this.client.rest.interactions.createInteractionResponse(this.id, this.token, { type: InteractionResponseTypes.PREMIUM_REQUIRED, data: {} });
325+
return this.client.rest.interactions.createInteractionResponse(this.id, this.token, { type: InteractionResponseTypes.PREMIUM_REQUIRED });
309326
}
310327

311328
/**

lib/types/applications.d.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import type {
1313
ApplicationVerificationState,
1414
EntitlementOwnerTypes,
1515
EntitlementTypes,
16+
EntryPointCommandHandlerTypes,
1617
InteractionContextTypes,
1718
RPCApplicationState,
1819
SKUAccessTypes,
@@ -120,6 +121,7 @@ export interface RawApplicationCommand {
120121
description_localized?: string;
121122
dm_permission?: boolean;
122123
guild_id?: string;
124+
handler?: EntryPointCommandHandlerTypes;
123125
id: string;
124126
integration_types: Array<ApplicationIntegrationTypes>;
125127
name: string;
@@ -173,19 +175,21 @@ export interface RawApplicationCommandOptionChoice {
173175
value: string | number;
174176
}
175177

176-
export type AnyApplicationCommand = ChatInputApplicationCommand | UserApplicationCommand | MessageApplicationCommand;
178+
export type AnyApplicationCommand = ChatInputApplicationCommand | UserApplicationCommand | MessageApplicationCommand | PrimaryEntryPointApplicationCommand;
177179
export type ApplicationCommandOptions = ApplicationCommandOptionsWithOptions | ApplicationCommandOptionsWithValue;
178180
export type ApplicationCommandOptionsWithOptions = ApplicationCommandOptionsSubCommand | ApplicationCommandOptionsSubCommandGroup;
179181
export type ApplicationCommandOptionsWithValue = ApplicationCommandOptionsString | ApplicationCommandOptionsInteger | ApplicationCommandOptionsBoolean | ApplicationCommandOptionsUser | ApplicationCommandOptionsChannel | ApplicationCommandOptionsRole | ApplicationCommandOptionsMentionable | ApplicationCommandOptionsNumber | ApplicationCommandOptionsAttachment;
180182
export type ChatInputApplicationCommand = ApplicationCommand<ApplicationCommandTypes.CHAT_INPUT>;
181183
export type UserApplicationCommand = ApplicationCommand<ApplicationCommandTypes.USER>;
182184
export type MessageApplicationCommand = ApplicationCommand<ApplicationCommandTypes.MESSAGE>;
185+
export type PrimaryEntryPointApplicationCommand = ApplicationCommand<ApplicationCommandTypes.PRIMARY_ENTRY_POINT>;
183186

184187
export type ApplicationCommandOptionConversion<T extends EditApplicationCommandOptions | CreateApplicationCommandOptions> =
185188
T extends EditChatInputApplicationCommandOptions | CreateChatInputApplicationCommandOptions ? ChatInputApplicationCommand :
186189
T extends EditUserApplicationCommandOptions | CreateUserApplicationCommandOptions ? UserApplicationCommand :
187190
T extends EditMessageApplicationCommandOptions | CreateMessageApplicationCommandOptions ? MessageApplicationCommand :
188-
never;
191+
T extends EditPrimaryEntryPointApplicationCommandOptions | CreatePrimaryEntryPointApplicationCommandOptions ? PrimaryEntryPointApplicationCommand :
192+
never;
189193

190194

191195
export interface ApplicationCommandOptionBase<T extends ApplicationCommandOptionTypes = ApplicationCommandOptionTypes> {
@@ -278,7 +282,7 @@ export interface CreateApplicationCommandOptionsBase<T extends ApplicationComman
278282
type: T;
279283
}
280284

281-
export type CreateApplicationCommandOptions = CreateChatInputApplicationCommandOptions | CreateUserApplicationCommandOptions | CreateMessageApplicationCommandOptions;
285+
export type CreateApplicationCommandOptions = CreateChatInputApplicationCommandOptions | CreateUserApplicationCommandOptions | CreateMessageApplicationCommandOptions | CreatePrimaryEntryPointApplicationCommandOptions;
282286
export interface CreateGuildChatInputApplicationCommandOptions extends Omit<CreateChatInputApplicationCommandOptions, "dmPermission" | "integrationTypes" | "contexts"> {}
283287
export interface CreateGuildUserApplicationCommandOptions extends Omit<CreateUserApplicationCommandOptions, "dmPermission" | "integrationTypes" | "contexts"> {}
284288
export interface CreateGuildMessageApplicationCommandOptions extends Omit<CreateMessageApplicationCommandOptions, "dmPermission" | "integrationTypes" | "contexts"> {}
@@ -292,13 +296,17 @@ export interface CreateChatInputApplicationCommandOptions extends CreateApplicat
292296
options?: Array<ApplicationCommandOptions>;
293297
}
294298

295-
export type CreateUserApplicationCommandOptions = CreateApplicationCommandOptionsBase<ApplicationCommandTypes.USER>;
296-
export type CreateMessageApplicationCommandOptions = CreateApplicationCommandOptionsBase<ApplicationCommandTypes.MESSAGE>;
299+
export interface CreateUserApplicationCommandOptions extends CreateApplicationCommandOptionsBase<ApplicationCommandTypes.USER> {}
300+
export interface CreateMessageApplicationCommandOptions extends CreateApplicationCommandOptionsBase<ApplicationCommandTypes.MESSAGE> {}
301+
export interface CreatePrimaryEntryPointApplicationCommandOptions extends CreateApplicationCommandOptionsBase<ApplicationCommandTypes.PRIMARY_ENTRY_POINT> {
302+
handler: EntryPointCommandHandlerTypes;
303+
}
297304

298-
export type EditApplicationCommandOptions = EditChatInputApplicationCommandOptions | EditUserApplicationCommandOptions | EditMessageApplicationCommandOptions;
305+
export type EditApplicationCommandOptions = EditChatInputApplicationCommandOptions | EditUserApplicationCommandOptions | EditMessageApplicationCommandOptions | EditPrimaryEntryPointApplicationCommandOptions;
299306
export interface EditChatInputApplicationCommandOptions extends Partial<Omit<CreateChatInputApplicationCommandOptions, "type">> {}
300307
export interface EditUserApplicationCommandOptions extends Partial<Omit<CreateUserApplicationCommandOptions, "type">> {}
301308
export interface EditMessageApplicationCommandOptions extends Partial<Omit<CreateMessageApplicationCommandOptions, "type">> {}
309+
export interface EditPrimaryEntryPointApplicationCommandOptions extends Partial<Omit<CreatePrimaryEntryPointApplicationCommandOptions, "type">> {}
302310

303311
export type EditGuildApplicationCommandOptions = EditGuildChatInputApplicationCommandOptions | EditGuildUserApplicationCommandOptions | EditGuildMessageApplicationCommandOptions;
304312
export interface EditGuildChatInputApplicationCommandOptions extends Partial<Omit<CreateChatInputApplicationCommandOptions, "type" | "dmPermission" | "integrationTypes" | "contexts">> {}

lib/types/interactions.d.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ export interface InteractionContent extends Pick<ExecuteWebhookOptions, "tts" |
4949
export interface EditInteractionContent extends Pick<EditWebhookMessageOptions, "content" | "embeds" | "allowedMentions" | "components" | "attachments" | "files"> {}
5050
export interface InitialInteractionContent extends Omit<InteractionContent, "attachments" | "files"> {}
5151

52-
export type InteractionResponse = PingInteractionResponse | MessageInteractionResponse | DeferredInteractionResponse | AutocompleteInteractionResponse | ModalSubmitInteractionResponse | PremiumRequiredResponse;
52+
export type InteractionResponse = PingInteractionResponse | MessageInteractionResponse | DeferredInteractionResponse | AutocompleteInteractionResponse | ModalSubmitInteractionResponse | PremiumRequiredResponse | LaunchActivityResponse;
5353
export interface PingInteractionResponse {
5454
type: InteractionResponseTypes.PONG;
5555
}
@@ -79,10 +79,13 @@ export interface ModalSubmitInteractionResponse {
7979
}
8080

8181
export interface PremiumRequiredResponse {
82-
data: Record<string, never>;
8382
type: InteractionResponseTypes.PREMIUM_REQUIRED;
8483
}
8584

85+
export interface LaunchActivityResponse {
86+
type: InteractionResponseTypes.LAUNCH_ACTIVITY;
87+
}
88+
8689

8790
export interface ModalData {
8891
/** The components of the modal. Each component needs its own row. `snake_case` keys should be converted to `camelCase`, or passed through {@link Util.rawModalComponents | Util#rawModalComponents}. */

lib/types/json.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ import type {
8484
ApplicationMonetizationState,
8585
RPCApplicationState,
8686
StoreApplicationState,
87-
ApplicationVerificationState
87+
ApplicationVerificationState,
88+
EntryPointCommandHandlerTypes
8889
} from "../Constants";
8990

9091
export interface JSONAnnouncementChannel extends JSONThreadableChannel {
@@ -143,6 +144,7 @@ export interface JSONApplicationCommand extends JSONBase {
143144
descriptionLocalizations?: LocaleMap | null;
144145
dmPermission?: boolean;
145146
guildID?: string;
147+
handler?: EntryPointCommandHandlerTypes;
146148
integrationTypes: Array<ApplicationIntegrationTypes>;
147149
name: string;
148150
nameLocalizations?: LocaleMap | null;

0 commit comments

Comments
 (0)