@tinypudding/discord-slash-commands

1.0.4 • Public • Published

Discord server NPM version NPM downloads Patreon Ko-Fi

npm installnfo

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

Package Sidebar

Install

npm i @tinypudding/discord-slash-commands

Weekly Downloads

0

Version

1.0.4

License

MIT

Unpacked Size

14.9 kB

Total Files

8

Last publish

Collaborators

  • jasmindreasond