
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
slash-commands
Advanced tools
This package provides Slash command support for the new Discord Interactions API.
This package provides Slash command support for the new Discord Interactions API.
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.
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
To import:
import { DiscordInteractions } from "slash-commands";
or
const { DiscordInteractions } = require("slash-commands");
const interaction = new DiscordInteractions({
applicationId: "1234567890",
authToken: "bot token",
publicKey: "discord-provided public key",
});
The following examples use
496279654483886100
as a guild id and545581357812678656
as a command id
// 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);
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);
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);
// 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);
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.
Help is much-needed to improve the library and add all features. Please feel free to make a PR to the repository.
FAQs
This package provides Slash command support for the new Discord Interactions API.
We found that slash-commands demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.