or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

assertions.mdcomponents-v2.mdcontext-menu-commands.mdembeds.mdindex.mdmessage-components.mdmodals.mdselect-menus.mdslash-commands.mdutilities.md
tile.json

slash-commands.mddocs/

Slash Commands

The slash command system provides builders for creating Discord application commands with full support for options, subcommands, localization, and permissions.

SlashCommandBuilder

Main builder for creating slash commands.

class SlashCommandBuilder {
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly options: ToAPIApplicationCommandOptions[];
  readonly contexts?: InteractionContextType[];
  readonly default_member_permissions?: Permissions | bigint | number | null;
  readonly dm_permission?: boolean;
  readonly default_permission?: boolean;
  readonly nsfw?: boolean;
  readonly integration_types?: ApplicationIntegrationType[];

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalization(locale: LocaleString, localizedName: string | null): this;
  setNameLocalizations(localizations: LocalizationMap | null): this;
  setDescriptionLocalization(locale: LocaleString, localizedDescription: string | null): this;
  setDescriptionLocalizations(localizations: LocalizationMap | null): this;
  setDefaultMemberPermissions(permissions: Permissions | bigint | number | null | undefined): this;
  setDMPermission(enabled: boolean | null | undefined): this;
  setDefaultPermission(value: boolean): this;
  setNSFW(nsfw?: boolean): this;
  setContexts(...contexts: InteractionContextType[]): this;
  setIntegrationTypes(...integrationTypes: ApplicationIntegrationType[]): this;
  
  // Option methods
  addStringOption(input: (builder: SlashCommandStringOption) => SlashCommandStringOption): this;
  addIntegerOption(input: (builder: SlashCommandIntegerOption) => SlashCommandIntegerOption): this;
  addBooleanOption(input: (builder: SlashCommandBooleanOption) => SlashCommandBooleanOption): this;
  addUserOption(input: (builder: SlashCommandUserOption) => SlashCommandUserOption): this;
  addChannelOption(input: (builder: SlashCommandChannelOption) => SlashCommandChannelOption): this;
  addRoleOption(input: (builder: SlashCommandRoleOption) => SlashCommandRoleOption): this;
  addMentionableOption(input: (builder: SlashCommandMentionableOption) => SlashCommandMentionableOption): this;
  addNumberOption(input: (builder: SlashCommandNumberOption) => SlashCommandNumberOption): this;
  addAttachmentOption(input: (builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption): this;
  
  // Subcommand methods  
  addSubcommand(input: (subcommand: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder): this;
  addSubcommandGroup(input: (subcommandGroup: SlashCommandSubcommandGroupBuilder) => SlashCommandSubcommandGroupBuilder): this;
  
  toJSON(): RESTPostAPIApplicationCommandsJSONBody;
}

Subcommands

SlashCommandSubcommandBuilder

Builder for individual subcommands within a slash command.

class SlashCommandSubcommandBuilder {
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly options: ToAPIApplicationCommandOptions[];

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalization(locale: LocaleString, localizedName: string | null): this;
  setNameLocalizations(localizations: LocalizationMap | null): this;
  setDescriptionLocalization(locale: LocaleString, localizedDescription: string | null): this;
  setDescriptionLocalizations(localizations: LocalizationMap | null): this;
  
  addStringOption(input: (builder: SlashCommandStringOption) => SlashCommandStringOption): this;
  addIntegerOption(input: (builder: SlashCommandIntegerOption) => SlashCommandIntegerOption): this;
  addBooleanOption(input: (builder: SlashCommandBooleanOption) => SlashCommandBooleanOption): this;
  addUserOption(input: (builder: SlashCommandUserOption) => SlashCommandUserOption): this;
  addChannelOption(input: (builder: SlashCommandChannelOption) => SlashCommandChannelOption): this;
  addRoleOption(input: (builder: SlashCommandRoleOption) => SlashCommandRoleOption): this;
  addMentionableOption(input: (builder: SlashCommandMentionableOption) => SlashCommandMentionableOption): this;
  addNumberOption(input: (builder: SlashCommandNumberOption) => SlashCommandNumberOption): this;
  addAttachmentOption(input: (builder: SlashCommandAttachmentOption) => SlashCommandAttachmentOption): this;
  
  toJSON(): APIApplicationCommandSubcommandOption;
}

SlashCommandSubcommandGroupBuilder

Builder for subcommand groups containing multiple subcommands.

class SlashCommandSubcommandGroupBuilder {
  readonly name: string;
  readonly description: string;
  readonly name_localizations?: LocalizationMap;
  readonly description_localizations?: LocalizationMap;
  readonly options: SlashCommandSubcommandBuilder[];

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalization(locale: LocaleString, localizedName: string | null): this;
  setNameLocalizations(localizations: LocalizationMap | null): this;
  setDescriptionLocalization(locale: LocaleString, localizedDescription: string | null): this;
  setDescriptionLocalizations(localizations: LocalizationMap | null): this;
  addSubcommand(input: (subcommand: SlashCommandSubcommandBuilder) => SlashCommandSubcommandBuilder): this;
  
  toJSON(): APIApplicationCommandSubcommandGroupOption;
}

Slash Command Options

SlashCommandStringOption

String input option with optional choices, autocomplete, min/max length.

class SlashCommandStringOption {
  readonly type: ApplicationCommandOptionType.String;
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly required?: boolean;
  readonly autocomplete?: boolean;
  readonly choices?: APIApplicationCommandOptionChoice<string>[];
  readonly min_length?: number;
  readonly max_length?: number;

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalizations(localizations: LocalizationMap): this;
  setDescriptionLocalizations(localizations: LocalizationMap): this;
  setRequired(required?: boolean): this;
  setAutocomplete(autocomplete: boolean): this;
  addChoices(...choices: APIApplicationCommandOptionChoice<string>[]): this;
  setChoices(...choices: APIApplicationCommandOptionChoice<string>[]): this;
  setMinLength(minLength: number): this;
  setMaxLength(maxLength: number): this;
  
  toJSON(): APIApplicationCommandStringOption;
}

SlashCommandIntegerOption

Integer input option with optional choices, autocomplete, min/max values.

class SlashCommandIntegerOption {
  readonly type: ApplicationCommandOptionType.Integer;
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly required?: boolean;
  readonly autocomplete?: boolean;
  readonly choices?: APIApplicationCommandOptionChoice<number>[];
  readonly min_value?: number;
  readonly max_value?: number;

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalizations(localizations: LocalizationMap): this;
  setDescriptionLocalizations(localizations: LocalizationMap): this;
  setRequired(required?: boolean): this;
  setAutocomplete(autocomplete: boolean): this;
  addChoices(...choices: APIApplicationCommandOptionChoice<number>[]): this;
  setChoices(...choices: APIApplicationCommandOptionChoice<number>[]): this;
  setMinValue(minValue: number): this;
  setMaxValue(maxValue: number): this;
  
  toJSON(): APIApplicationCommandIntegerOption;
}

SlashCommandNumberOption

Number (decimal) input option with optional choices, autocomplete, min/max values.

class SlashCommandNumberOption {
  readonly type: ApplicationCommandOptionType.Number;
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly required?: boolean;
  readonly autocomplete?: boolean;
  readonly choices?: APIApplicationCommandOptionChoice<number>[];
  readonly min_value?: number;
  readonly max_value?: number;

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalizations(localizations: LocalizationMap): this;
  setDescriptionLocalizations(localizations: LocalizationMap): this;
  setRequired(required?: boolean): this;
  setAutocomplete(autocomplete: boolean): this;
  addChoices(...choices: APIApplicationCommandOptionChoice<number>[]): this;
  setChoices(...choices: APIApplicationCommandOptionChoice<number>[]): this;
  setMinValue(minValue: number): this;
  setMaxValue(maxValue: number): this;
  
  toJSON(): APIApplicationCommandNumberOption;
}

SlashCommandBooleanOption

Boolean true/false option.

class SlashCommandBooleanOption {
  readonly type: ApplicationCommandOptionType.Boolean;
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly required?: boolean;

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalizations(localizations: LocalizationMap): this;
  setDescriptionLocalizations(localizations: LocalizationMap): this;
  setRequired(required?: boolean): this;
  
  toJSON(): APIApplicationCommandBooleanOption;
}

SlashCommandUserOption

User selection option.

class SlashCommandUserOption {
  readonly type: ApplicationCommandOptionType.User;
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly required?: boolean;

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalizations(localizations: LocalizationMap): this;
  setDescriptionLocalizations(localizations: LocalizationMap): this;
  setRequired(required?: boolean): this;
  
  toJSON(): APIApplicationCommandUserOption;
}

SlashCommandChannelOption

Channel selection option with optional channel type restrictions.

class SlashCommandChannelOption {
  readonly type: ApplicationCommandOptionType.Channel;
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly required?: boolean;
  readonly channel_types?: ChannelType[];

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalizations(localizations: LocalizationMap): this;
  setDescriptionLocalizations(localizations: LocalizationMap): this;
  setRequired(required?: boolean): this;
  addChannelTypes(...channelTypes: ChannelType[]): this;
  setChannelTypes(...channelTypes: ChannelType[]): this;
  
  toJSON(): APIApplicationCommandChannelOption;
}

SlashCommandRoleOption

Role selection option.

class SlashCommandRoleOption {
  readonly type: ApplicationCommandOptionType.Role;
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly required?: boolean;

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalizations(localizations: LocalizationMap): this;
  setDescriptionLocalizations(localizations: LocalizationMap): this;
  setRequired(required?: boolean): this;
  
  toJSON(): APIApplicationCommandRoleOption;
}

SlashCommandMentionableOption

Mentionable (user or role) selection option.

class SlashCommandMentionableOption {
  readonly type: ApplicationCommandOptionType.Mentionable;
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly required?: boolean;

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalizations(localizations: LocalizationMap): this;
  setDescriptionLocalizations(localizations: LocalizationMap): this;
  setRequired(required?: boolean): this;
  
  toJSON(): APIApplicationCommandMentionableOption;
}

SlashCommandAttachmentOption

File attachment option.

class SlashCommandAttachmentOption {
  readonly type: ApplicationCommandOptionType.Attachment;
  readonly name: string;
  readonly name_localizations?: LocalizationMap;
  readonly description: string;
  readonly description_localizations?: LocalizationMap;
  readonly required?: boolean;

  constructor();
  setName(name: string): this;
  setDescription(description: string): this;
  setNameLocalizations(localizations: LocalizationMap): this;
  setDescriptionLocalizations(localizations: LocalizationMap): this;
  setRequired(required?: boolean): this;
  
  toJSON(): APIApplicationCommandAttachmentOption;
}

Usage Examples

Basic Slash Command

import { SlashCommandBuilder } from "@discordjs/builders";

const pingCommand = new SlashCommandBuilder()
  .setName('ping')
  .setDescription('Replies with Pong!');

Slash Command with Options

const banCommand = new SlashCommandBuilder()
  .setName('ban')
  .setDescription('Ban a user from the server')
  .addUserOption(option =>
    option
      .setName('target')
      .setDescription('The user to ban')
      .setRequired(true)
  )
  .addStringOption(option =>
    option
      .setName('reason')
      .setDescription('The reason for the ban')
      .setRequired(false)
  );

Slash Command with Subcommands

const configCommand = new SlashCommandBuilder()
  .setName('config')
  .setDescription('Server configuration commands')
  .addSubcommandGroup(group =>
    group
      .setName('settings')
      .setDescription('Server settings configuration')
      .addSubcommand(subcommand =>
        subcommand
          .setName('prefix')
          .setDescription('Set the bot prefix')
          .addStringOption(option =>
            option
              .setName('value')
              .setDescription('The new prefix')
              .setRequired(true)
              .setMaxLength(5)
          )
      )
  );

Slash Command with Choices

const weatherCommand = new SlashCommandBuilder()
  .setName('weather')
  .setDescription('Get weather information')
  .addStringOption(option =>
    option
      .setName('location')
      .setDescription('Select a location')
      .setRequired(true)
      .addChoices(
        { name: 'New York', value: 'ny' },
        { name: 'London', value: 'london' },
        { name: 'Tokyo', value: 'tokyo' }
      )
  );

Types

type ToAPIApplicationCommandOptions = 
  | APIApplicationCommandSubcommandOption
  | APIApplicationCommandSubcommandGroupOption
  | APIApplicationCommandBasicOption;

interface LocalizationMap {
  [locale: string]: string;
}

interface APIApplicationCommandOptionChoice<ValueType = string | number> {
  name: string;
  name_localizations?: LocalizationMap;
  value: ValueType;
}