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 🙏

© 2025 – Pkg Stats / Ryan Hefner

djs-slash-commands

v2.3.1

Published

A wrapper meant to incorporate discord.js slash commands into your Discord bot.

Downloads

8

Readme

Discord.js Slash Commands!

A wrapper meant to incorporate discord.js slash commands into your Discord bot.

Installation

$ npm i --save djs-slash-commands

Usage

Required:

Importing and initializing the handler:

const { SlashCommandHandler } = require("djs-slash-commands");
client.SlashCommands = new SlashCommandHandler(client);

Receiving the interaction:

Note: You must reply in 3 seconds. To get past this limit, defer the interaction, or use followUps.

client.on("slashCreate", async (interaction) => {
  if (interaction.commandName === "somecommand")
    return interaction.reply("Some reply...");
  if (interaction.commandName === "someothercommand")
    return interaction.reply("This is an ephemeral.", { ephemeral: true });

  // Sending a followup message:
  if (interaction.commandName === "ping") {
    interaction.reply("Ping?!");
    interaction.followUp("Pong!");
  }

  // Editing & deleting reply.
  if (interaction.commandName === "thatonecommand") {
    await interaction.reply("REPLIED?!");
    await interaction.editReply("EDITED?!");
    // DELETED?!
    interaction.deleteReply();
  }

  // Deferring an interaction. Makes it say "{Name} is thinking..." and gives you 15 minutes to reply.
  if (interaction.commandName === "defer") {
    interaction.defer();
    setTimeout(
      async () => await interaction.reply("I have stopped thinking."),
      9000
    );
  }
});

Global Commands:

Option Types:

| Name | Value | | ----------------- | ----- | | SUB_COMMAND | 1 | | SUB_COMMAND_GROUP | 2 | | STRING | 3 | | INTEGER | 4 | | BOOLEAN | 5 | | USER | 6 | | CHANNEL | 7 | | ROLE | 8 | | MENTIONABLE | 9 |

Base Object:
const baseObject = {
  name: "ping",
  description: "Pong?!",
};

// Or, with options:

const baseObject = {
  name: "ping",
  description: "pong?!",
  options: [
    {
      name: "someoption",
      description: "some description",
      type: "USER",
    },
  ],
};

client.slashCommands.add(baseObject);

Bulk adding global slash commands:

Warning: This removes all other slash commands your bot has.

const baseObject2 = {
  name: "othercommand",
  description: "ANOTHER COMMAND?!",
};
client.SlashCommands.bulkAdd([baseObject, baseObject2]);

Guild-Specific Commands:

client.SlashCommands.add(baseObject, "GuildID");

Bulk add guild-specific slash commands:

Warning: This removes all other slash commands..

client.SlashCommands.bulkAdd(
  [baseObject, baseObject2]
  "GuildID"
);

Viewing/Deleting the Command:

client.on("ready", async () => {
  /**
   * Viewing the command(s).
   */

  const cmds = await client.SlashCommands.get();
  console.log(cmds); // Logs all slash commands.

  // Guild Commands:
  const guildCmds = await client.SlashCommands.get(null, "GuildID");
  console.log(guildCmds); // Logs all guild commands.

  // For the following methods, you must get the ID. You can do so by using the methods above, as they all return a command object with the property ID.

  // For specific commands:
  const cmd = await client.SlashCommands.get("ID");
  console.log(cmd);

  // For guild-specific commands:
  const guildCmd = await client.SlashCommands.get("ID", "GuildID");
  console.log(guildCmd);

  /**
   * Deleting the command(s).
   * For the following methods, you must get the ID. You can do so by using the methods above, as they all return a command object with the property ID.

   */

  // Global command:
  await client.SlashCommands.delete("ID");

  // Guild-Specific command:
  await client.SlashCommands.delete("ID", "GuildID");
});

Interaction Properties:

| Name | Value | Purpose | | --------------------- | ----------------------------------------- | -------------------------------------------------------------- | | client | Discord.Client | Client that initiated the interaction. | | type | Boolean | Interaction type. | | isCommand | Boolean | Whether interaction is a command. | | channel | Discord.TextChannel | Channel interaction occured in. | | channelID | String | Channel interaction occured in's ID. | | guild | Discord.Guild | Guild the interaction occured in. | | guildID | String | Guild the interaction occured in's ID. | | member | Discord.GuildMember | Guild member who used the interaction. null if in DMs. | | memberID | String | Guild member who used the interaction's ID. null if in DMs. | | commandName | String | Interaction command name. | | commandID | String | Interaction command ID. | | author | Discord.User | User who used interaction. | | authorID | String | User who used the interaction's ID. | | options | Discord.Collection | Arguments provided for interaction. | | id | String | Interaction ID. | | createdDate | DjsSlashCommands.Timestamp (custom class) | When the interaction was created's date. | | createdTimestampEpoch | Number | When the interaction was created, relative to Discord's Epoch. | | createdTimestamp | Date | When the interaction was created's timestamp. | | token | String | Interaction token. | | applicationID | String | Interaction application ID. | | webhook | Discord.WebhookClient | Webhook client for sending followup messages. | | replied | Boolean | Whether the interaction has been replied to. | | deferred | Boolean | Whether the interaction has been deferred to. | | raw | Object | Raw interaction object returned from the API. |

Application Command Properties

| Name | Value | Purpose | | --------------------- | ------------------------------------ | -------------------------------------------------------------------------- | | name | String | Command name. | | id | String | Command ID. | | client | String | Client that initiated the command. | | applicationID | String | Command application ID. | | description | String | Command description. | | options | Array | Command options. | | version | String | Command version. | | guildID | String | Command Guild ID. null if global command. | | guild | Discord.Guild | Command Guild. null if global command. | | createdTime | DjsSlashCommands.Timestamp | Interaction created time object. (Custom class) | | createdTimestamp | Date | Command creation timestamp. | | createdTimestampEpoch | Number | Command creation timestamp, relative to Discord's epoch. | | defaultPermissions | Boolean | Whether the command will be added when the client is added to a new guild. | | type | Number | Command type. | | SlashCommandHandler | DjsSlashCommands.SlashCommandHandler | Slash command handler that initiated this command. |