slash-create-modify
Version:
Create and sync Discord slash commands!
214 lines (213 loc) • 8.64 kB
TypeScript
import { ApplicationCommandOption, ApplicationCommandPermissions, ApplicationCommandType, PartialApplicationCommand } from './constants';
import { CommandContext } from './structures/interfaces/commandContext';
import { SlashCreator } from './creator';
import { AutocompleteContext } from './structures/interfaces/autocompleteContext';
/** Represents a Discord slash command. */
export declare class SlashCommand<T = any> {
/** The command's name. */
readonly commandName: string;
/** The localiztions for the command name. */
nameLocalizations?: Record<string, string>;
/** The type of command this is. */
readonly type: ApplicationCommandType;
/** The command's description. */
readonly description?: string;
/** The localiztions for the command description. */
descriptionLocalizations?: Record<string, string>;
/** The options for the command. */
options?: ApplicationCommandOption[];
/** The guild ID(s) for the command. */
readonly guildIDs?: string[];
/** The default member permissions required to use the command. */
readonly requiredPermissions?: string[];
/** Whether to check the member's permission within command execution, regardless of admin-set command permissions. */
readonly forcePermissions: boolean;
/** The throttling options for this command. */
readonly throttling?: ThrottlingOptions;
/** Whether this command is used for unknown commands. */
readonly unknown: boolean;
/** Whether responses from this command should defer ephemeral messages. */
readonly deferEphemeral: boolean;
/**
* Whether to enable this command for everyone by default.'
* @deprecated
*/
readonly defaultPermission: boolean;
/** Whether to enable this command in direct messages. */
readonly dmPermission: boolean;
/**
* The command permissions per guild.
* @deprecated Command permissions have been deprecated: https://link.snaz.in/sc-cpd
*/
readonly permissions?: CommandPermissions;
/**
* The file path of the command.
* Used for refreshing the require cache.
* Set this to `__filename` in the constructor to enable cache clearing.
*/
filePath?: string;
/**
* A map of command IDs with its guild ID (or 'global' for global commands), used for syncing command permissions.
* This will populate when syncing or collecting with {@link SlashCreator#collectCommandIDs}.
*/
ids: Map<string, string>;
/** The creator responsible for this command. */
readonly creator: SlashCreator;
/** Current throttle objects for the command, mapped by user ID. */
private _throttles;
/**
* @param creator The instantiating creator.
* @param opts The options for the command.
*/
constructor(creator: SlashCreator, opts: SlashCommandOptions);
/**
* The JSON for using commands in Discord's API.
* @private
* @deprecated Use {@link SlashCommand#toCommandJSON} instead.
*/
get commandJSON(): PartialApplicationCommand;
/**
* The command object serialized into JSON.
* @param global Whether the command is global or not.
*/
toCommandJSON(global?: boolean): PartialApplicationCommand;
/**
* The internal key name for the command.
* @private
*/
get keyName(): string;
/** The client passed from the creator */
get client(): T;
/**
* Checks whether the context member has permission to use the command.
* @param ctx The triggering context
* @return {boolean|string} Whether the member has permission, or an error message to respond with if they don't
*/
hasPermission(ctx: CommandContext): boolean | string;
/**
* Called when the command is prevented from running.
* @param ctx Command context the command is running from
* @param reason Reason that the command was blocked
* (built-in reasons are `permission`, `throttling`)
* @param data Additional data associated with the block.
* - permission: `response` ({@link string}) to send
* - throttling: `throttle` ({@link Object}), `remaining` ({@link number}) time in seconds
*/
onBlock(ctx: CommandContext, reason: string, data?: any): any;
/**
* Called when the command produces an error while running.
* @param err Error that was thrown
* @param ctx Command context the command is running from
*/
onError(err: Error, ctx: CommandContext): any;
/**
* Called when the command's localization is requesting to be updated.
*/
onLocaleUpdate(): any;
/**
* Called when the command is being unloaded.
*/
onUnload(): any;
/**
* Creates/obtains the throttle object for a user, if necessary.
* @param userID ID of the user to throttle for
* @private
*/
throttle(userID: string): ThrottleObject | null;
/** Reloads the command. */
reload(): void;
/** Unloads the command. */
unload(): void;
/**
* Runs the command.
* @param ctx The context of the interaction
*/
run(ctx: CommandContext): Promise<any>;
/**
* Runs an autocomplete function.
* @param ctx The context of the interaction
*/
autocomplete(ctx: AutocompleteContext): Promise<any>;
/**
* Finalizes the return output
* @param response The response from the command
* @param ctx The context of the interaction
* @private
*/
finalize(response: any, ctx: CommandContext): any;
/**
* Validates {@link SlashCommandOptions}.
* @private
*/
static validateOptions(opts: SlashCommandOptions): void;
}
export declare const Command: typeof SlashCommand;
/** The options for a {@link SlashCommand}. */
export interface SlashCommandOptions {
/** The type of command this is. Defaults to chat input, or a regular slash command. */
type?: ApplicationCommandType;
/** The name of the command. */
name: string;
/** The localiztions for the command name. */
nameLocalizations?: Record<string, string>;
/** The description of the command. */
description?: string;
/** The localiztions for the command description. */
descriptionLocalizations?: Record<string, string>;
/** The guild ID(s) that this command will be assigned to. */
guildIDs?: string | string[];
/** The default member permissions required to use the command. Use an empty array to resemble a `false` default permission. */
requiredPermissions?: string[];
/** Whether to check the member's permission within command execution, regardless of admin-set command permissions. */
forcePermissions?: boolean;
/** The command's options. */
options?: ApplicationCommandOption[];
/** The throttling options for the command. */
throttling?: ThrottlingOptions;
/** Whether this command is used for unknown commands. */
unknown?: boolean;
/** Whether responses from this command should defer ephemeral messages. */
deferEphemeral?: boolean;
/**
* Whether to enable this command for everyone by default. `true` by default.
* @deprecated Use {@link SlashCommandOptions.requiredPermissions} and {@link SlashCommandOptions.dmPermission} instead.
*/
defaultPermission?: boolean;
/** Whether to enable this command in direct messages. `true` by default. */
dmPermission?: boolean;
/**
* The command permissions per guild
* @deprecated Command permissions have been deprecated: https://link.snaz.in/sc-cpd
*/
permissions?: CommandPermissions;
}
/**
* The command permission for a {@link SlashCommand}.
* The object is a guild ID mapped to an array of {@link ApplicationCommandPermissions}.
* @example
* {
* '<guild_id>': [
* {
* type: ApplicationCommandPermissionType.USER,
* id: '<user_id>',
* permission: true
* }
* ]
* }
*/
export interface CommandPermissions {
[guildID: string]: ApplicationCommandPermissions[];
}
/** The throttling options for a {@link SlashCommand}. */
export interface ThrottlingOptions {
/** Maximum number of usages of the command allowed in the time frame. */
usages: number;
/** Amount of time to count the usages of the command within (in seconds). */
duration: number;
}
/** @private */
export interface ThrottleObject {
start: number;
usages: number;
timeout: any;
}