New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

djs-commands

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

djs-commands

a command handler for slash commands on discordjs

latest
Source
npmnpm
Version
3.0.2
Version published
Weekly downloads
43
514.29%
Maintainers
1
Weekly downloads
 
Created
Source

djs-commands

an all-in-one command handler package.

NPM Version Downloads Stats

Installation

npm install djs-commands

Setup guide

1 - Require and create a CommandHandler instance

Pass through the Discord Client instantiated from Discord.js, your token (this may be optional in the future but is needed to register slash commands), and the folder path that houses your command files.

const { CommandHandler } = require("djs-commands");
const handler = new CommandHandler(client, token, folder_path);

2 - In the interactionCreate event is where we will run our command

client.on("interactionCreate", async (interaction) => {
  if (!interaction.isChatInputCommand()) return;

  let cmd = handler.getCommand(interaction.commandName);
  if (!cmd) return;
  try {
    cmd.run(interaction);
  } catch (e) {
    console.log(e);
  }
});

3 - And of course we're going to need a command file. So inside of your bot folder, create a folder called commands. I'm going to create a file called test.js and put the following code inside of it.

The this.slashCommand option takes a SlashCommandBuilder() passed as a JSON type. You can add whatever slash command options you like here using discordjs/builders.

const { SlashCommandBuilder } = require("discordjs");
module.exports = class test {
  constructor() {
    ((this.name = "test"),
      (this.slashCommand = new SlashCommandBuilder()
        .setName("test")
        .setDescription("A command to test stuff and things.")));
  }

  async run(interaction) {
    await interaction.reply(this.name + " works");
  }
};

4 - And that's it! You have a working command handler now for all the commands you could want! Here's an example of how to add options to a slash command.

const { SlashCommandBuilder } = require("discordjs");
module.exports = class another {
  constructor() {
    ((this.name = "another"),
      (this.slashCommand = new SlashCommandBuilder()
        .setName("another")
        .setDescription("Another command to test stuff and things.")
        .addBooleanOption((option) =>
          option
            .setName("stuff")
            .setDescription("a description")
            .setRequired(true),
        )));
  }

  async run(interaction) {
    await interaction.reply(this.name + " works");
  }
};

And then from there, you can add as many options or whatever type of option you wish using the link above.

https://github.com/nedinator/djs-commands

Contributing

  • Fork it (https://github.com/nedinator/djs-commands/fork)
  • Create your feature branch (git checkout -b feature/fooBar)
  • Commit your changes (git commit -am 'Add some fooBar')
  • Push to the branch (git push origin feature/fooBar)
  • Create a new Pull Request

FAQs

Package last updated on 11 Feb 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts