Ninja Pumpkin Mutants

    @sapphire/plugin-subcommands
    TypeScript icon, indicating that this package has built-in type declarations

    3.2.3 • Public • Published

    Sapphire Logo

    @sapphire/plugin-subcommands

    Plugin for @sapphire/framework so your commands can have subcommands.

    GitHub codecov npm bundle size npm

    Description

    Subcommands are a way to split 1 command into multiple. This can in particular be very useful for configuration commands with subcommands such as set, reset and remove.

    Features

    • Fully ready for TypeScript!
    • Includes ESM ready entrypoint
    • Type generics for easy extension in TypeScript
    • Input/Output mapping

    Installation

    @sapphire/plugin-subcommands depends on the following packages. Be sure to install these along with this package!

    You can use the following command to install this package, or replace npm install with your package manager of choice.

    npm install @sapphire/plugin-subcommands @sapphire/framework @sapphire/utilities discord.js

    Usage

    Start by importing the registration file in your project to use the plugins error loggers:

    JavaScript

    require('@sapphire/plugin-subcommands/register');

    TypeScript

    import '@sapphire/plugin-subcommands/register';

    Then, you can create new subcommands by extending the Subcommand class. With TypeScript:

    import { Subcommand } from '@sapphire/plugin-subcommands';
    import { ApplyOptions } from '@sapphire/decorators';
    import type { Args } from '@sapphire/framework';
    import type { Message, CommandInteraction } from 'discord.js';
    
    // Using ApplyOptions decorator makes it easy to configure
    @ApplyOptions<Subcommand.Options>({
    	subcommands: [
    		{
    			name: 'add',
    			messageRun: 'messageAdd',
    			chatInputRun: 'chatInputAdd'
    		},
    		{
    			name: 'remove',
    			messageRun: 'messageRemove',
    			chatInputRun: 'chatInputRemove'
    		},
    		{
    			name: 'list',
    			messageRun: 'messageList',
    			chatInputRun: 'chatInputList'
    		}
    	]
    })
    // Extend `Subcommand` instead of `Command`
    export class UserCommand extends Subcommand {
    	public async messageAdd(message: Message, args: Args) {}
    
    	public async messageRemove(message: Message, args: Args) {}
    
    	public async messageList(message: Message, args: Args) {}
    
    	public async chatInputAdd(interaction: Subcommand.ChatInputInteraction) {}
    
    	public async chatInputRemove(interaction: Subcommand.ChatInputInteraction) {}
    
    	public async chatInputList(interaction: Subcommand.ChatInputInteraction) {}
    }

    With JavaScript:

    const { Subcommand } = require('@sapphire/plugin-subcommands');
    
    // Extend `Subcommand` instead of `Command`
    module.exports = class UserCommand extends Subcommand {
    	constructor(context, options) {
    		super(context, {
    			...options,
    			subcommands: [
    				{
    					name: 'add',
    					messageRun: 'messageAdd',
    					chatInputRun: 'chatInputAdd'
    				},
    				{
    					name: 'remove',
    					messageRun: 'messageRemove',
    					chatInputRun: 'chatInputRemove'
    				},
    				{
    					name: 'list',
    					messageRun: 'messageList',
    					chatInputRun: 'chatInputList'
    				}
    			]
    		});
    	}
    
    	async messageAdd(message, args) {}
    
    	async messageRemove(message, args) {}
    
    	async messageList(message, args) {}
    
    	async chatInputAdd(interaction) {}
    
    	async chatInputRemove(interaction) {}
    
    	async chatInputList(interaction) {}
    };

    For more documentation please refer to guide

    Buy us some doughnuts

    Sapphire Community is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

    We accept donations through Open Collective, Ko-fi, Paypal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.

    Donate With Address
    Open Collective Click Here
    Ko-fi Click Here
    Patreon Click Here
    PayPal Click Here

    Contributors

    Thanks goes to these wonderful people (emoji key):


    Jeroen Claassens

    💻 🚇 📆

    Nejc Drobnic

    💻 📖

    Antonio Román

    💻

    Vlad Frangu

    👀

    depfu[bot]

    🚧

    dependabot[bot]

    🚧

    allcontributors[bot]

    📖

    Tyler J Russell

    💻 📖

    Stitch07

    💻 🐛

    PlatinBae

    📖

    Kaname

    💻 📖

    Elliot

    💻

    Lioness100

    💻 📖

    UndiedGamer

    💻

    Feralheart

    💻

    Jurien Hamaker

    💻

    renovate[bot]

    🚧

    WhiteSource Renovate

    🚧

    c43721

    💻

    megatank58

    💻

    FC

    💻

    Just a Badly Drawn TABS Dude

    💻

    newt :D

    💻

    Mzato

    💻

    Harry Allen

    💻

    Julian

    💻

    Krish

    💻

    Parbez

    💻

    ricardooow

    💻

    Hezekiah Hendry

    🔧

    yuansheng1549

    💻

    Ben

    💻

    Priyam

    💻

    This project follows the all-contributors specification. Contributions of any kind welcome!

    Install

    npm i @sapphire/plugin-subcommands

    DownloadsWeekly Downloads

    1,270

    Version

    3.2.3

    License

    MIT

    Unpacked Size

    85.5 kB

    Total Files

    44

    Last publish

    Collaborators

    • favna
    • kyranet
    • vladfrangu