SlashCommandBuilder
SlashCommandBuilder 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 { SlashCommandBuilder } from "lunibee";import { SlashCommandBuilder } from "lunibee";Methods
Section titled “Methods”setName(name)
Section titled “setName(name)”Sets the command name (1–32 chars, lowercase, no spaces — use hyphens).
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.
import { Permission } from "lunibee";command.setDefaultMemberPermissions(Permission.banMembers);import { Permission } from "lunibee";command.setDefaultMemberPermissions(Permission.banMembers);setDMPermission(allowed)
Section titled “setDMPermission(allowed)”Whether the command can be used in DMs.
command.setDMPermission(false);command.setDMPermission(false);Option Builders
Section titled “Option Builders”Each option type has a corresponding method. All return this.
| 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.
Examples
Section titled “Examples”Simple ping command
import { SlashCommandBuilder } from "lunibee";
const ping = new SlashCommandBuilder() .setName("ping") .setDescription("Replies with Pong!");
await client.application.commands.create(ping.toJSON());import { SlashCommandBuilder } from "lunibee";
const ping = new SlashCommandBuilder() .setName("ping") .setDescription("Replies with Pong!");
await client.application.commands.create(ping.toJSON());Ban command with options
const ban = new SlashCommandBuilder() .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 SlashCommandBuilder() .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 SlashCommandBuilder() .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 SlashCommandBuilder() .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") );