Skip to content

Commit

Permalink
feat: support entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Sep 17, 2024
1 parent 7282979 commit 979ec3d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
11 changes: 11 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ApplicationCommandOption,
ApplicationCommandType,
ApplicationIntegrationType,
EntryPointHandlerType,
InteractionContextType,
PartialApplicationCommand,
PermissionNames
Expand Down Expand Up @@ -49,6 +50,8 @@ export class SlashCommand<T = any> {
readonly integrationTypes: ApplicationIntegrationType[];
/** The contexts where this command can be used. */
readonly contexts: InteractionContextType[];
/** For entry point commands, determines how this command is handled either by the app or Discord */
readonly handler?: EntryPointHandlerType;
/**
* The file path of the command.
* Used for refreshing the require cache.
Expand Down Expand Up @@ -84,6 +87,7 @@ export class SlashCommand<T = any> {
if (opts.descriptionLocalizations) this.descriptionLocalizations = opts.descriptionLocalizations;
this.options = opts.options;
if (opts.guildIDs) this.guildIDs = typeof opts.guildIDs == 'string' ? [opts.guildIDs] : opts.guildIDs;
if (opts.handler) this.handler = opts.handler;
this.requiredPermissions = opts.requiredPermissions;
this.forcePermissions = typeof opts.forcePermissions === 'boolean' ? opts.forcePermissions : false;
this.nsfw = typeof opts.nsfw === 'boolean' ? opts.nsfw : false;
Expand Down Expand Up @@ -134,6 +138,11 @@ export class SlashCommand<T = any> {
}
: {})
}
: {}),
...(this.type === ApplicationCommandType.ENTRY_POINT
? {
handler: this.handler
}
: {})
};
}
Expand Down Expand Up @@ -387,6 +396,8 @@ export interface SlashCommandOptions {
integrationTypes?: ApplicationIntegrationType[];
/** The contexts where this command can be used. */
contexts?: InteractionContextType[];
/** For entry point commands, whether to have the application or Discord handle this command. */
handler?: EntryPointHandlerType;
}

/** The throttling options for a {@link SlashCommand}. */
Expand Down
12 changes: 11 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,17 @@ export enum ApplicationCommandType {
/** A UI-based command that shows up when you right click or tap on a user */
USER = 2,
/** A UI-based command that shows up when you right click or tap on a messages */
MESSAGE = 3
MESSAGE = 3,
/** A UI-based command that represents the primary way to invoke an app's Activity */
ENTRY_POINT = 4
}

/** The types of handlers an entry point supports. */
export enum EntryPointHandlerType {
/** The app handles the interaction using an interaction token */
APP_HANDLER = 1,
/** Discord handles the interaction by launching an Activity and sending a follow-up message without coordinating with the app */
DISCORD_LAUNCH_ACTIVITY = 2
}

/** The types of channels in Discord channels. */
Expand Down

0 comments on commit 979ec3d

Please sign in to comment.