Skip to content

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 { SlashCommandBuilder } from "lunibee";

Sets the command name (1–32 chars, lowercase, no spaces — use hyphens).

command.setName("ban");

Sets the command description (1–100 characters).

command.setDescription("Bans a member from the server.");

Sets the default member permissions required to see and use the command.

import { Permission } from "lunibee";
command.setDefaultMemberPermissions(Permission.banMembers);

Whether the command can be used in DMs.

command.setDMPermission(false);

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
command.addStringOption(option =>
option
.setName("reason")
.setDescription("Why you're banning this user")
.setRequired(true)
.setMaxLength(500)
);

Returns the Discord API-compatible command payload object.

Simple ping command

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)
);

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")
);