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

slash-commands

v1.5.0

Published

This package provides Slash command support for the new Discord Interactions API.

Downloads

535

Readme

discord-slash-commands

This package provides Slash command support for the new Discord Interactions API.

npm npm bundle size npm downloads

We've documented every type used by the interactions API, so you can make use of this library in your own projects, or make use of the utility functions we've provided to create, get, and delete slash commands.

Installation

This is a Node.js module available from the npm registry.

You can install it with npm

npm install slash-commands

or with Yarn

yarn add slash-commands

Importing

To import:

import { DiscordInteractions } from "slash-commands";

or

const { DiscordInteractions } = require("slash-commands");

Initialization

const interaction = new DiscordInteractions({
  applicationId: "1234567890",
  authToken: "bot token",
  publicKey: "discord-provided public key",
});

Usage

The following examples use 496279654483886100 as a guild id and 545581357812678656 as a command id

Getting Commands

// Get Global Commands
await interaction
  .getApplicationCommands()
  .then(console.log)
  .catch(console.error);

// Get Guild Commands
await interaction
  .getApplicationCommands("496279654483886100")
  .then(console.log)
  .catch(console.error);

Creating Commands

const command = {
  name: "avatar",
  description: "get a users avatar",
  options: [
    {
      name: "big",
      description: "should the image be big",
      type: ApplicationCommandOptionType.BOOLEAN,
    },
  ],
};

// Create Global Command
await interaction
  .createApplicationCommand(command)
  .then(console.log)
  .catch(console.error);

// Create Guild Command
await interaction
  .createApplicationCommand(command, "496279654483886100")
  .then(console.log)
  .catch(console.error);

Editing Commands

const command = {
  name: "avatar",
  description: "get a users avatar",
  options: [
    {
      name: "small",
      description: "should the image be small",
      type: ApplicationCommandOptionType.BOOLEAN,
    },
  ],
};

// Edit Global Command
await interaction
  .createApplicationCommand(command, null, "545581357812678656")
  .then(console.log)
  .catch(console.error);

// Edit Guild Command
await interaction
  .createApplicationCommand(command, "496279654483886100", "545581357812678656")
  .then(console.log)
  .catch(console.error);

Deleting Commands

// Delete Global Command
await interaction
  .deleteApplicationCommand("545581357812678656")
  .then(console.log)
  .catch(console.error);

// Delete Guild Command
await interaction
  .deleteApplicationCommand("545581357812678656", "496279654483886100")
  .then(console.log)
  .catch(console.error);

Disclaimer

The slash command API is incomplete, so this library is likely to have breaking changes on non-major releases.

Once the slash command API is stable, we will bump the project to v2.0.0.

Contributing

Help is much-needed to improve the library and add all features. Please feel free to make a PR to the repository.