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

djs-commands

v2.0.7

Published

a command handler for slash commands on discordjs v14

Downloads

171

Readme

djs-commands

an all-in-one command handler package.

NPM Version Downloads Stats

Djs-commands currently includes a command handler for your Discord.JS bots.

UPDATE v2.0.0 MAJOR CHANGE

Hi! So over the years this bot has become more and more deprecated, and with the switch to slash commands, I decided to accommodate for that. This update is mostly for me to continue to use the same handler I've used for years with actual support for the recent changes with Discordjs, but it still remains open source on github with the link below.

djs-commands Discord Help Server

I set up a support server, it's minimal for now. I noticed a surge in downloads when I updated and assume many were from the videos and with it being extremely different, figured this would help. Also, any contribution questions/discussions can take place here. Click here to join

Installation

npm install djs-commands discord.js @discordjs/builders dotenv

Setup guide

1 - Setup .env in the root folder of the bot

CLIENT_ID=CLIENTIDHERE
GUILD_ID=CLIENTIDHERE
TOKEN=BOTTOKENHERE

2 - Require and create a CommandHandler instance

const { CommandHandler } = require("djs-commands");
const CH = new CommandHandler({
  folder: __dirname + "/commands/",
  guildCommandRefresh: true, //not including this or setting as false reverts to not updating GUILD commands.
});

Another option is to use guildCommandRefresh: true to just refresh guild commands from the ID in .env.

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

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

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

4 - 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/builders");
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");
  }
};

5 - 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/builders");
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

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