import * as discord_js from 'discord.js'; import { Collection, CacheType } from 'discord.js'; import { container, Command as Command$1, Args, CommandJSON, AliasPiece, CommandOptionsRunType, CommandRunInUnion, CommandSpecificRunIn, ApplicationCommandRegistry } from '@sapphire/framework'; import { SlashCommandSubcommandBuilder, SlashCommandBuilder } from '@discordjs/builders'; import { Subcommand as Subcommand$1, SubcommandOptions as SubcommandOptions$1 } from '@sapphire/plugin-subcommands'; /** * **Subcommand options** * * Options to register a command as a subcommand of a parent command. * * @since 1.0.0 */ interface SubcommandOptions { registerSubCommand?: { parentCommandName: string; slashSubcommand?: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder, Container: typeof container) => SlashCommandSubcommandBuilder); }; registerSubcommandInGroup?: { parentCommandName: string; groupName: string; slashSubcommand?: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder, Container: typeof container) => SlashCommandSubcommandBuilder); }; } type CommandOptions = SubcommandOptions; interface SubcommandMappingCollection { slashCommand?: SlashCommandSubcommandBuilder; commandPiece: Command$1; } /** * Internal plugin options of `@kaname-png/plugin-subcommands-advanced` * * Defines options to control the plugin behavior. * * @since 1.2.2 */ interface PluginSubcommandOptions { /** * Update the `name` option of the command options with a name auto-generated by the plugin. * * This does not change the name of the subcommand as such, it only changes the `name` property of the command's internal options. * * This helps to keep command classes from collapsing with repeated names (@sapphire/pieces does not load 2 pieces with the same name) and avoids having to manually put a special name for each command. * * **Subcommands** * * @example Subcommands * ``` * Parent command = "utils" * Subcommand name = "ping" * Name autogenerated = "utils/ping" * ``` * * **Subcommands group** * * @example * ``` * Parent command = "search" * Group name = "anime" * Subcommand name = "watch" * Name autogenerated = "search/anime/watch" * ``` * * @since 1.2.2 */ nameCommandsAutogenerated?: boolean; } /** * **Events** * * Names of events that will be called when a subcommand does not comply with the preconditions established in the command options. * These events are specific to the plugin. * * @since 1.0.0 */ declare const SubcommandsAdvancedEvents: { ChatInputSubcommandDenied: "chatInputSubcommandDenied"; MessageSubcommandDenied: "messageSubcommandDenied"; }; /** * **Registry** * * Subcommands registry. * * @since 1.0.0 */ declare const subCommandsRegistry: Collection>; /** * **Registry** * * Subcommands group registry. * * @since 1.0.0 */ declare const subCommandsGroupRegistry: Collection>>; /** * **Command** * * Command class extended from the original `@sapphire/framework` class that includes the methods to register subcommands based on command class. * * It is necessary to have a parent command that manages the subcommands configured with the plugin. The name of the parent command must be the same as the one set in the `prentCommandName` option of the command options. * * When creating the chatInputRun and messageRun methods (both are optional but one of them must always exist) the method will be automatically linked in the subcommand of the parent command. * * **Register the command as a subcommand in a parent command** * * To register commands as subcommands of the parent command it is necessary to use the `registerSubCommand` option of the command options. * * *Parent command* * * ```typescript * import { SubCommand } from '@kaname-png/plugin-subcommands-advanced'; * import { ApplicationCommandRegistry } from '@sapphire/framework'; * * export class ParentCommand extends SubCommand { * public constructor(context: Command.Context, options: Command.Options) { * super(context, { * ...options, * name: 'utils' * }); * } * * public override registerApplicationCommands(interaction: ApplicationCommandRegistry) { * registry.registerChatInputCommand( * (ctx) => { * // It is necessary to call this hook and pass the builder context to register the subcommands stored in the subcommand register in the parent command. * this.hooks.subcommands(this, ctx); * * return ctx * .setName(this.name) * .setDescription('Parent command of utils subcommands) * } * ); * } * } * ``` * * *With Typescript* * ```typescript * import { SubCommand } from '@kaname-png/plugin-subcommands-advanced' * * export class UtilsCommand extends SubCommand { * public constructor(context: Command.Context, options: Command.Options) { * super(context, { * ...options, * registerSubCommand: { * parentCommandName: 'utils', // Name of the parent command (parent.js). * subcommand: (builder) => builder.setName('ping').setDescription('Hi!') // Builder that will be embedded in the registry of the parent command. * } * }); * } * * public override chatInputRun(interaction: Command.ChatInputInteraction) { * return interaction.reply('uwu'); * } * } * ``` * * *With JavaScript* * * ```javascript * import { Command } from '@kaname-png/plugin-subcommands-advanced' * * export class UtilsCommand extends Command { * constructor(context, options) { * super(context, { * ...options, * registerSubCommand: { * parentCommandName: 'utils', // Name of the parent command (parent.js). * subcommand: (builder) => builder.setName('ping').setDescription('Hi!') // Builder that will be embedded in the registry of the parent command. * } * }); * } * * chatInputRun(interaction) { * return interaction.reply('uwu'); * } * } * ``` * * **Register a command as a subcommand of a group of subcommands of the parent command** * * To register commands as group subcommands it is important to first register the groups to be used in the main command. * * *Parent command* * * ```typescript * import { SubCommand } from '@kaname-png/plugin-subcommands-advanced'; * import { ApplicationCommandRegistry } from '@sapphire/framework'; * * export class ParentCommand extends SubCommand { * public constructor(context: Command.Context, options: Command.Options) { * super(context, { * ...options, * name: 'utils' * }); * } * * public override registerApplicationCommands(interaction: ApplicationCommandRegistry) { * registry.registerChatInputCommand( * (ctx) => { * // First it is necessary to register the subcommand groups in the context of the constructor. * ctx.addSubcommandGroup((sc) => * sc * .setName('poll') * .setDescription('Make awesome polls!') * ); * * // It is necessary to call this hook and pass the constructor context to register the subcommands stored in the subcommand registry in the subcommand groups of the parent command. * this.hooks.groups(this, ctx); * * return ctx * .setName(this.name) * .setDescription('Parent command of utils subcommands) * } * ); * } * } * ``` * * *With Typescript* * * ```typescript * import { Command } from '@kaname-png/plugin-subcommands-advanced' * * export class PollCreateCommand extends Command { * public constructor(context: Command.Context, options: Command.Options) { * super(context, { * ...options, * registerSubCommand: { * parentCommandName: 'utils', // Name of the parent command (parent.js). * groupName: 'poll', // Name of the group that was registered in the builder context of the parent command. * subcommand: (builder) => builder.setName('create').setDescription('Create a poll') // Builder that will be embedded in the registry of the parent command. * } * }); * } * * public override chatInputRun(interaction: Command.ChatInputInteraction) { * return interaction.reply('uwu'); * } * } * ``` * * *With JavaScript* * * ```javascript * import { Command } from '@kaname-png/plugin-subcommands-advanced' * * export class PollCreateCommand extends Command { * constructor(context, options) { * super(context, { * ...options, * registerSubCommand: { * parentCommandName: 'utils', // Name of the parent command (parent.js). * groupName: 'poll', // Name of the group that was registered in the builder context of the parent command. * subcommand: (builder) => builder.setName('create').setDescription('Create a poll') // Builder that will be embedded in the registry of the parent command. * } * }); * } * * chatInputRun(interaction) { * return interaction.reply('uwu'); * } * } * ``` * * That's it, the plugin will take care of configuring everything so that when the subcommand of the parent command is called, the linked command is executed. * * @since 1.0.0 */ declare class Command extends Command$1 { constructor(context: Command.LoaderContext, options: Command.Options); } declare namespace Command { type Options = CommandOptions & Command$1.Options; type JSON = CommandJSON; /** @deprecated Use {@linkcode LoaderContext} instead. */ type Context = LoaderContext; type LoaderContext = AliasPiece.LoaderContext<'commands'>; type RunInTypes = CommandOptionsRunType; type RunInUnion = CommandRunInUnion; type SpecificRunIn = CommandSpecificRunIn; type ChatInputCommandInteraction = Command$1.ChatInputCommandInteraction; type ContextMenuCommandInteraction = Command$1.ContextMenuCommandInteraction; type AutocompleteInteraction = Command$1.AutocompleteInteraction; type Registry = ApplicationCommandRegistry; } /** * **Parent command** * * Subcommand class that extends the original subcommand plugin class and incorporates the hooks into the class for ease of use. * * The parent command is important because it is where the subcommands and subcommand group will be registered and is necessary for `@sapphire/framework` to know what to do with the subcommands. * * *TypeScript* * * ```typescript * import { Subcommand } from '@kaname-png/plugin-subcommands-advanced'; * import { ApplicationCommandRegistry } from '@sapphire/framework'; * * export class ParentCommand extends Subcommand { * public constructor(context: Subcommand.Context, options: Subcommand.Options) { * super(context, { * ...options, * name: 'utils' * }); * } * * public override registerApplicationCommands(interaction: ApplicationCommandRegistry) { * registry.registerChatInputCommand( * (ctx) => { * // If you want to link commands in groups of subcommands you first need to register them in the builder context of the parent command. * ctx.addSubcommandGroup((sc) => * sc * .setName('poll') * .setDescription('Make awesome polls!') * ); * * // It is necessary to call this hook and pass the constructor context to register the subcommands stored in the subcommand registry in the subcommand groups of the parent command. * this.hooks.groups(this, ctx); * * // It is necessary to call this hook and pass the builder context to register the subcommands stored in the subcommand register in the parent command. * this.hooks.subcommands(this, ctx); * * // Calling both hooks is only necessary if required, it is not mandatory. * return ctx * .setName(this.name) * .setDescription('Parent command of utils subcommands') * } * ); * } * } * ``` * * *JavaScript* * * ```javascript * import { Subcommand } from '@kaname-png/plugin-subcommands-advanced'; * * export class ParentCommand extends Subcommand { * public constructor(context, options) { * super(context, { * ...options, * name: 'utils' * }); * } * * public override registerApplicationCommands(interaction) { * registry.registerChatInputCommand( * (ctx) => { * // If you want to link commands in groups of subcommands you first need to register them in the builder context of the parent command. * ctx.addSubcommandGroup((sc) => * sc * .setName('poll') * .setDescription('Make awesome polls!') * ); * * // It is necessary to call this hook and pass the constructor context to register the subcommands stored in the subcommand registry in the subcommand groups of the parent command. * this.hooks.groups(this, ctx); * * // It is necessary to call this hook and pass the builder context to register the subcommands stored in the subcommand register in the parent command. * this.hooks.subcommands(this, ctx); * * // Calling both hooks is only necessary if required, it is not mandatory. * return ctx * .setName(this.name) * .setDescription('Parent command of utils subcommands'); * } * ); * } * } * ``` * * @since 1.0.0 */ declare class Subcommand extends Subcommand$1 { hooks: { subcommands: (piece: Subcommand$1, context?: discord_js.SlashCommandBuilder | undefined) => void; groups: (piece: Subcommand$1, context?: discord_js.SlashCommandBuilder | undefined) => void; }; } declare namespace Subcommand { type Options = SubcommandOptions$1; type JSON = Command$1.JSON; /** @deprecated Use {@linkcode LoaderContext} instead. */ type Context = LoaderContext; type LoaderContext = Command$1.LoaderContext; type RunInTypes = Command$1.RunInTypes; type ChatInputCommandInteraction = Command$1.ChatInputCommandInteraction; type ContextMenuCommandInteraction = Command$1.ContextMenuCommandInteraction; type AutocompleteInteraction = Command$1.AutocompleteInteraction; type Registry = Command$1.Registry; } /** * **Hooks** * * Methods needed to register commands as subcommands and commands in subcommand groups. * * @since 1.0.0 */ declare const RegisterSubcommandsHooks: { subcommands: (piece: Subcommand$1, context?: SlashCommandBuilder) => void; groups: (piece: Subcommand$1, context?: SlashCommandBuilder) => void; }; declare const RegisterSubCommand: (parentCommandName: string, Subcommand?: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder, Container: typeof container) => SlashCommandSubcommandBuilder)) => ClassDecorator; declare const RegisterSubCommandGroup: (parentCommandName: string, groupName: string, Subcommand?: SlashCommandSubcommandBuilder | ((subcommandGroup: SlashCommandSubcommandBuilder, Container: typeof container) => SlashCommandSubcommandBuilder)) => ClassDecorator; export { Command, type CommandOptions, type PluginSubcommandOptions, RegisterSubCommand, RegisterSubCommandGroup, RegisterSubcommandsHooks, Subcommand, type SubcommandMappingCollection, type SubcommandOptions, SubcommandsAdvancedEvents, subCommandsGroupRegistry, subCommandsRegistry };