CreateSlashCommand
CreateSlashCommand creates the JSON payload needed to register a slash command with Discord. It does not send any network requests — use the ApplicationCommandManager or client.rest to register the payload.
Import
Section titled “Import”import { CreateSlashCommand } from "lunibee";import { CreateSlashCommand } from "lunibee";Methods
Section titled “Methods”setName(name)
Section titled “setName(name)”Sets the command name (1–32 lowercase letters, numbers, underscores or hyphens; no spaces). Anything else throws a RangeError.
command.setName("ban");command.setName("ban");setDescription(description)
Section titled “setDescription(description)”Sets the command description (1–100 characters).
command.setDescription("Bans a member from the server.");command.setDescription("Bans a member from the server.");setDefaultMemberPermissions(permissions)
Section titled “setDefaultMemberPermissions(permissions)”Sets the default member permissions required to see and use the command (a bigint, number or string, serialized as a string; null clears it).
import { Permission } from "lunibee";command.setDefaultMemberPermissions(Permission.banMembers);import { Permission } from "lunibee";command.setDefaultMemberPermissions(Permission.banMembers);setContexts(...contexts)
Section titled “setContexts(...contexts)”Where the command can be used: 0 guilds, 1 the bot’s DMs, 2 other DMs. Any other value throws a RangeError.
command.setContexts(0); // guilds onlycommand.setContexts(0); // guilds onlysetDMPermission(allowed) (removed)
Section titled “setDMPermission(allowed) (removed)”Removed in 0.3.1, as Discord deprecated dm_permission. Use setContexts() instead: setDMPermission(false) becomes setContexts(0), and, for a guild-installed bot, setDMPermission(true) becomes setContexts(0, 1).
setIntegrationTypes(...types)
Section titled “setIntegrationTypes(...types)”Where the command can be installed: 0 guild install, 1 user install.
setNSFW(nsfw?)
Section titled “setNSFW(nsfw?)”Marks the command as age-restricted (nsfw defaults to true). setNsfw() is an alias.
Option Builders
Section titled “Option Builders”Each option type has a corresponding method taking a configure callback. All return this. A command holds at most 25 options with unique names, and required options must come before optional ones (otherwise a RangeError is thrown).
| Method | Option Type |
|---|---|
addStringOption(fn) |
Text input |
addIntegerOption(fn) |
Whole number |
addNumberOption(fn) |
Float |
addBooleanOption(fn) |
True/false |
addUserOption(fn) |
Discord user picker |
addChannelOption(fn) |
Channel picker |
addRoleOption(fn) |
Role picker |
addMentionableOption(fn) |
User or role picker |
addAttachmentOption(fn) |
File attachment |
addSubcommand(fn) |
Subcommand |
addSubcommandGroup(fn) |
Subcommand group |
Option method signature
Section titled “Option method signature”command.addStringOption(option => option .setName("reason") .setDescription("Why you're banning this user") .setRequired(true) .setMaxLength(500));command.addStringOption(option => option .setName("reason") .setDescription("Why you're banning this user") .setRequired(true) .setMaxLength(500));toJSON()
Section titled “toJSON()”Returns the Discord API-compatible command payload object (type: 1).
Examples
Section titled “Examples”Simple ping command
import { CreateSlashCommand } from "lunibee";
const ping = new CreateSlashCommand() .setName("ping") .setDescription("Replies with Pong!");
await client.application.commands.create(ping); // builders are accepted as they areimport { CreateSlashCommand } from "lunibee";
const ping = new CreateSlashCommand() .setName("ping") .setDescription("Replies with Pong!");
await client.application.commands.create(ping); // builders are accepted as they areBan command with options
const ban = new CreateSlashCommand() .setName("ban") .setDescription("Bans a member from the server") .addUserOption(option => option.setName("target").setDescription("User to ban").setRequired(true) ) .addStringOption(option => option.setName("reason").setDescription("Reason for the ban") ) .addIntegerOption(option => option .setName("delete_days") .setDescription("Days of messages to delete (0-7)") .setMinValue(0) .setMaxValue(7) );const ban = new CreateSlashCommand() .setName("ban") .setDescription("Bans a member from the server") .addUserOption(option => option.setName("target").setDescription("User to ban").setRequired(true) ) .addStringOption(option => option.setName("reason").setDescription("Reason for the ban") ) .addIntegerOption(option => option .setName("delete_days") .setDescription("Days of messages to delete (0-7)") .setMinValue(0) .setMaxValue(7) );Command with subcommands
const settings = new CreateSlashCommand() .setName("settings") .setDescription("Manage bot settings") .addSubcommand(sub => sub .setName("prefix") .setDescription("Change the bot prefix") .addStringOption(opt => opt.setName("value").setDescription("New prefix").setRequired(true)) ) .addSubcommand(sub => sub.setName("reset").setDescription("Reset all settings to defaults") );const settings = new CreateSlashCommand() .setName("settings") .setDescription("Manage bot settings") .addSubcommand(sub => sub .setName("prefix") .setDescription("Change the bot prefix") .addStringOption(opt => opt.setName("value").setDescription("New prefix").setRequired(true)) ) .addSubcommand(sub => sub.setName("reset").setDescription("Reset all settings to defaults") );Option builder classes
Section titled “Option builder classes”Each addXOption(fn) callback receives a new instance of one of these classes and must return it.
| Class | Option type | Extra methods |
|---|---|---|
CreateStringOption |
3 | addChoices({ name, value }), setMinLength, setMaxLength, setAutocomplete |
CreateIntegerOption |
4 | addChoices, setMinValue, setMaxValue (integers only), setAutocomplete |
CreateNumberOption |
10 | addChoices, setMinValue, setMaxValue, setAutocomplete |
CreateBooleanOption |
5 | — |
CreateUserOption |
6 | — |
CreateChannelOption |
7 | addChannelTypes(...types) |
CreateRoleOption |
8 | — |
CreateMentionableOption |
9 | — |
CreateAttachmentOption |
11 | — |
All of them have setName, setDescription (1-100 characters), setRequired(required = true) and setAutocomplete(enabled = true). Choices must be strings of 1-100 characters or finite numbers (at most 25), choices cannot be added to an autocomplete option, and an option with choices refuses autocomplete, setMinLength / setMaxLength take 0-6000 / 1-6000, and setMinValue / setMaxValue throw a RangeError if the minimum would exceed the maximum.
Subcommands
Section titled “Subcommands”addSubcommand(fn) adds a CreateSubcommand (type 1), which takes the same addXOption methods. addSubcommandGroup(fn) adds a CreateSubcommandGroup (type 2), whose only children are subcommands (at most 25, unique names).
const config = new CreateSlashCommand() .setName("config") .setDescription("Bot settings") .addSubcommandGroup((group) => group .setName("prefix") .setDescription("Prefix settings") .addSubcommand((sub) => sub .setName("set") .setDescription("Change the prefix") .addStringOption((o) => o.setName("value").setDescription("New prefix").setRequired(true)), ), );In the handler, interaction.options.getSubcommandGroup() and getSubcommand() tell you which one ran.