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

@ming-suhi/djs-commando

v3.0.0

Published

A package to easily create and manage your Discord Slash Commands.

Downloads

19

Readme

@ming-suhi/djs-commando

I. About

A discord.js extension for easily building and receiving your Discord Slash Commands. For an in-depth documentation visit the documentation website. Or join the support server to talk with the developer. Please note that this package is not affiliated with discord.js.

II. Quick Start

A. Installing

Run npm install on the command line or terminal.
npm install @ming-suhi/djs-commando

B. Creating a Command

To create a command, start by making a file inside a designated folder. Require/import the needed command class from @ming-suhi/djs-commando. Top level command classes include SlashCommand, MessageCommand, and UserCommand. To create a command, extend the chosen class and set its name and description in the constructor(MessageCommand and UserCommand doesn't have a description). Add an execute method with one parameter of Interaction type. This method will run if the command is called by a user from Discord. Finally, for command to be handled by the package, export it with module.exports.

const { SlashCommand } = require('@ming-suhi/djs-commando');

const command = new class extends SlashCommand {
  constructor() {
    super();
    this.name = "ping";
    this.description = "get ponged";
  }

  async execute(interaction) {
    await interaction.reply("pong");
  }
}

module.exports = command;

C. Adding Command Options

A SlashCommand can take on options which includes subcommands, subcommand groups and fields. To create a subcommand, import Subcommand from @ming-suhi/djs-commando, and create a new class extending Subcommand and set its name and description in the constructor. To attach the subcommand to a SlashCommand or subcommand group pass it inside super. Creating a subcommand group is similar to creating a subcommand. Available fields are StringField, IntegerField, BooleanField, UserField, ChannelField, RoleField, MentionableField, NumberField, and AttachmentField. To create a field, create a new instance of the chosen field class which takes on 3 arguments: a name and description and a boolean that states if the field is required. Attach it to a Slashcommand or Subcommand inside super.

const { SlashCommand, Subcommand, StringField } = require('@ming-suhi/djs-commando');

const message = new StringField('message', 'message to echo', true);

const subcommand = new class extends Subcommand {
  constructor() {
    super([message]);
    this.name = "message";
    this.description = "echos a message";
  }

  async execute(interaction) {
    const messageArg = interaction.options.getString("message");
    await interaction.reply(messageArg);
  }
}

const command = new class extends SlashCommand {
  constructor() {
    super([subcommand]);
    this.name = "echo";
    this.description = "echo commands";
  }
}

module.exports = command; // Only export top command

D. Registering Commands

Before receiving commands, load all commands. First, require InteractionsHandler from @ming-suhi/djs-commando. Create new instance of InteractionsHandler and call loadCommands method. The method requires one argument which is the path to the commands folder.

const { InteractionsHandler } = require('@ming-suhi/djs-commando');

const handler = new InteractionsHandler();
handler.loadCommands("ABSOLUTE/PATH/TO/COMMANDS/FOLDER");

E. Receiving Commands

To receive commands, call handleInteraction method on interactionCreate event. Interactions handler will manage getting the matching command and executing it when interaction is received.

client.on('interactionCreate', async interaction => {
  await handler.handleInteraction(interaction);
});

F. Posting Commands

Optionally, you can install @ming-suhi/djsc-cli to easily manage(post, delete, update) your commands from the command line.

npm install @ming-suhi/djsc-cli
//djsc.config.js
const { mapCommands } = require("@ming-suhi/djs-commando");

module.exports = {
  appId: "DISCORD_APP_ID",
  botToken: "DISCORD_BOT_TOKEN",
  mapCommands: () => mapCommands("ABSOLUTE/PATH/TO/COMMANDS/FOLDER")
}

III. Contributing

A. Issues

This project uses GitHub Issues to track bugs and feature requests. Please search the existing issues before filing new issues to avoid duplicates. For new issues, file your bug or feature request as a new issue.

For help and questions about using this project, please open a GitHub issue.

B. Pull requests

  1. Fork the project.

  2. Create a topic branch from master.

  3. Make some commits to improve the project.

  4. Push this branch to your GitHub project.

  5. Open a Pull Request on GitHub.

  6. Discuss, and optionally continue committing.

V. License

MIT © 明suhi