Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

slash-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

slash-commands

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

  • 1.5.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.3K
increased by53.08%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 30 Jul 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc