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

@tinypudding/discord-slash-commands

v1.0.4

Published

A simple way to interact and manage discord slash-commands

Downloads

11

Readme

Discord-Interactions-JS

A simple way to interact and manage discord slash-commands.

Credits

This module has been forked to be adapted to the scripts of the Tiny Pudding Server repositories. The first version was made by https://github.com/MatteZ02/discord-interactions.

Usage

You need to choose whether to type a Bot Token or a User Token.

const interactions = require("@tinypudding/discord-slash-commands");

const client = new interactions.Client({
    bot_token: "you unique bot token",
    client_id: "your bots user id",
    user_token: "you unique user token"
});

List all your existing commands.

client.getCommands().then(console.log).catch(console.error);

Will create a new command and log its data. If a command with this name already exist will that be overwritten.

client
  .createCommand({
    name: "unique command name",
    description: "description for this unique command",
  })
  .then(console.log)
  .catch(console.error);

Will edit the details of a command.

client
  .editCommand(
    { name: "new command name", description: "new command description" },
    "id of the command you wish to edit"
  )
  .then(console.log)
  .catch(console.error);

will delete a command

client
  .deleteCommand("id of the command you wish to delete")
  .then(console.log)
  .catch(console.error);

API

Passing a guildID is optional. Doing so will make the command only be available on that guild. Guild commands update instantly. We recommend you use guild commands for quick testing, and global commands when they're ready for public use.

Discord api documentation on slash commands

getCommands(options: getCommandOptions) returns Promise< array of ApplicationOptions>

  • getCommandsOptions - List of options can be found here.

createCommand(options: ApplicationCommandOptions, guildID?: string) returns Promise

  • ApplicationOptions - List of options can be found here.
  • guildID - guild to create this command on.

editCommand(options: ApplicationCommandOptions, commandID: string, guildID?: string) returns Promise

  • ApplicationOptions - List of options can be found here.
  • commandID - ID of the command you wish to edit.
  • guildID - If the command is a part of a guild you must pass the guildID here.

deleteCommand(commandID: string, guildID?: string) returns Promise

  • commandID - ID of the command you wish to delete.
  • guildID - If the command is a part of a guild you must pass the guildID here.

Options

Properties marked with ? are optional.

ApplicationCommandOption

{
    name: "name of this unique command",
    description: "description for this unique command",
    options?: [
        {
        name: "name of this option",
        description: "description for this option",
        type: 1,// Type for this option. for a list of types see https://discord.com/developers/docs/interactions/slash-commands#applicationcommandoptiontype
        default?: true,
        required?: true,
        choices?: [
            {
                name: "string to prefill for this choice",
                value: "value of this choice that will be returned when command is used."
            }
        ]
        }
    ]
}
{
  name: "name of the command";
  description: "description of the command";
  options?: Array of ApplicationCommandOption;
}

getCommandsOptions

{
  commandID?: "id of the command you wish to get",
  guildID?: "if the command is a part of a guild u should put the guild id here"
}

Types

You can find a list of Data Models and Types from here.

Interaction with the command

You can setup a webhook-based interaction. You can read more about how to do this from the documentation.

interaction example response

channel: Discord.TextChannel;// The channel where this interaction occured
guild: Discord.Guild;// The guild where this interaction occured
member: Discord.GuildMember | null;// The guild member who issued the interaction (will be null if we cannot obtain a guildMember)
author: Discord.User | null;// The user who issued the interaction (will be null if we cannot obtain an user)
name: string;// name of this command
content: string;// content of this command (everything after the main command name)
createdTimestamp: number;// timestamp of this command being used
options: { value: string; name: string }[] | null;// list of options this user inputted to the command