Coder Social home page Coder Social logo

00-00-00-11 / discord-slash-commands-1 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meguminsama/discord-slash-commands

0.0 1.0 0.0 110 KB

Node.JS Slash Commands for Discord

License: MIT License

Shell 0.22% JavaScript 23.52% TypeScript 76.27%

discord-slash-commands-1's Introduction

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.

discord-slash-commands-1's People

Contributors

a5rocks avatar gaminggeek avatar meguminsama avatar rodentman87 avatar sharpdev-me avatar vendicated avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.