npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@elenoragroup/simple-slash

v1.0.6

Published

A simple Command Builder for Discord.

Downloads

108

Readme

About

@elenoragroup/simple-slash is a utility package for building the Discord Slash Commands JSON simply.

Installation

This was built with Node.js v18.12.1.

    npm install @elenoragroup/simple-slash

Links

Examples

Base Command

    import SimpleSlash from '@elenoragroup/simple-slash';

    // Create the definition for the command
    const definition = new SimpleSlash('ping', 'Pings the bot.');

    // value of definition
    SimpleSlash {
        name: 'ping',
        description: 'Pings the bot.',
        options: [],
        type: undefined
    }

Arguments

StringOption

Parameters

    StringOption(
        name: string,
        description: string,
        required = false,
        autocomplete = false,
        choices?: string[], //Optional; Length must be between 2 and 25.
        min_length?: number, //Optional; Min number of characters to be passed in
        max_length?: number, //Optional; Max number of characters to be passed in
    )

Base StringOption

    import SimpleSlash from '@elenoragroup/simple-slash';

    // Create the definition for the command
    const definition = new SimpleSlash('stats', "Look up someone's stats").StringOption('name', "Who's stats would you like to see?");

    // value of definition
    SimpleSlash {
      name: 'stats',
      description: "Look up someone's stats",
      options: [
        {
          name: 'name',
          description: "Who's stats would you like to see?",
          type: 3,
          choices: [],
          required: false,
          autocomplete: false,
          min_length: undefined,
          max_length: undefined
        }
      ],
      type: undefined
    }

StringOption with Choices - Choices are automatically lowercased and all spaces replaced with _ for the value.

    import SimpleSlash from '@elenoragroup/simple-slash';

    // Create the definition for the command
    const definition = new SimpleSlash('stats', "Look up someone's stats")
        .StringOption('name', "Who's stats would you like to see?", true, false, ['Timmy', 'Peter', 'Jimmy John']);

    // value of definition
    SimpleSlash {
      name: 'stats',
      description: "Look up someone's stats",
      options: [
        {
          name: 'name',
          description: "Who's stats would you like to see?",
          type: 3,
          choices: [
            {
                name: 'Timmy',
                value: 'timmy'
            },
            {
                name: 'Peter',
                value: 'peter'
            },
            {
                name: 'Jimmy John',
                value: 'jimmy_john'
            },
          ],
          required: true,
          autocomplete: false,
          min_length: undefined,
          max_length: undefined
        }
      ],
      type: undefined
    }

IntegerOption | NumberOption

Parameters

    IntegerOption(
        name: string,
        description: string,
        required = false,
        autocomplete = false,
        min_value?: number, //Optional; Min value of the number to be passed in
        max_value?: number, //Optional; Max value of the number to be passed in
        choices?: number[], //Optional; Length must be between 2 and 25.
    )

Base IntegerOption | NumberOption

    import SimpleSlash from '@elenoragroup/simple-slash';

    // Create the definition for the command
    const definition = new SimpleSlash('puppies', 'See puppies.').IntegerOption('amount', 'How many puppies would you like to see?');

    // value of definition
    SimpleSlash {
      name: 'puppies',
      description: 'See puppies.',
      options: [
        {
          name: 'amount',
          description: 'How many puppies would you like to see?',
          type: 4, //NumberOption would return `10` here.
          required: false,
          min_value: undefined,
          max_value: undefined
          choices: []
        }
      ],
      type: undefined
    }

ChannelOption

Parameters

    ChannelOption(
        name: string,
        description: string,
        channelType: ChannelType[], //Will need to import ChannelTypes
        required = false
    )

Base ChannelOption

    import SimpleSlash, { ChannelTypes } from '@elenoragroup/simple-slash';

    // Create the definition for the command
    const definition = new SimpleSlash('set_channel', 'Set a channel for posts.')
        .ChannelOption('channel_name', 'What channel would you like to set?', [ChannelType.GUILD_TEXT, ChannelType.GUILD_ANNOUNCEMENT]);

    // value of definition
    SimpleSlash {
      name: 'set_channel',
      description: 'Set a channel for posts.',
         options: [
           {
             name: 'channel_name',
             description: 'What channel would you like to set?',
             type: 7,
             channel_types: [0, 5], //Only allows the command to display announcement and text channels
             required: false
           }
      ],
      type: undefined
    }

BooleanOption | UserOption | RoleOption | MentionableOption | AttachmentOption

Parameters

    UserOption(
        name: string,
        description: string,
        required = false
    )

Base BooleanOption | UserOption | RoleOption | MentionableOption | AttachmentOption

    import SimpleSlash from '@elenoragroup/simple-slash';

    // Create the definition for the command
    const definition = new SimpleSlash('profile', "See someone's profile.").UserOption('user', "Who's profile would you like to see?");

    // value of definition
    SimpleSlash {
      name: 'profile',
      description: "See someone's profile.",
         options: [
           {
             name: 'user',
             description: "Who's profile would you like to see?",
             type: 6, //Boolean: 5, Role: 8, Mentionable: 9, Attachment: 11
             required: false
           }
      ],
      type: undefined
    }

Subcommand | SubcommandGroup

Parameters

    Subcommand(
        name: string,
        description: string,
        cb?: (builder: SimpleSlash) => void
    )

Base Subcommand | SubcommandGroup

    import SimpleSlash from '@elenoragroup/simple-slash';

    // Create the definition for the command
    const definition = new SimpleSlash('boxes', 'Do things with boxes.').Subcommand('list', 'List all current boxes.')

    // value of definition
    SimpleSlash {
      name: 'boxes',
      description: 'Do things with boxes.',
      options: [
        SimpleSlash {
            name: 'list',
            description: 'List all current boxes.',
            options: [],
            type: 1
        }
      ],
      type: undefined
    }

Nested Command

import SimpleSlash from '@elenoragroup/simple-slash';

const definition = new SimpleSlash('purchase', 'Buy things')
    .SubcommandGroup('bottoms', 'Pants, shorts, etc.', (command) =>
        command
            .Subcommand('pants', 'Buy pants', (command) =>
                command
                    .StringOption('type', 'What type of pants would you like to buy?', true, false, ['jeans', 'sweats', 'joggers'])
                    .StringOption('size', 'What size would you like to buy?', true, false, ['small', 'medium', 'large'])
                    .StringOption('color', 'What color would you like to buy?', true, false, ['black', 'blue', 'white'])
                    .IntegerOption('quantity', 'How many would you like to buy?', true, 1, 10),
            )
            .Subcommand('shorts', 'Buy shorts', (command) =>
                command
                    .StringOption('type', 'What type of shorts would you like to buy?', true, false, ['jeans', 'sweats', 'cargo'])
                    .StringOption('size', 'What size would you like to buy?', true, false, ['small', 'medium', 'large'])
                    .StringOption('color', 'What color would you like to buy?', true, false, ['black', 'blue', 'white'])
                    .IntegerOption('quantity', 'How many would you like to buy?', true, 1, 10),
            ),
    )
    .SubcommandGroup('tops', 'Shirts, jackets, etc.', (command) =>
        command
            .Subcommand('shirts', 'Buy shirts', (command) =>
                command
                    .StringOption('type', 'What type of shirt would you like to buy?', true, false, ['t-shirt', 'long-sleeve'])
                    .StringOption('size', 'What size would you like to buy?', true, false, ['small', 'medium', 'large'])
                    .StringOption('color', 'What color would you like to buy?', true, false, ['black', 'blue', 'white'])
                    .IntegerOption('quantity', 'How many would you like to buy?', true, 1, 10),
            )
            .Subcommand('jackets', 'Buy jackets', (command) =>
                command
                    .StringOption('type', 'What type of jacket would you like to buy?', true, false, ['raincoat', 'puffer', 'parka'])
                    .StringOption('size', 'What size would you like to buy?', true, false, ['small', 'medium', 'large'])
                    .StringOption('color', 'What color would you like to buy?', true, false, ['black', 'blue', 'white'])
                    .IntegerOption('quantity', 'How many would you like to buy?', true, 1, 10),
            ),
    );