UNPKG

@oceanicjs/builders

Version:

Helpful builders for various Discord related things.

68 lines (67 loc) 4.88 kB
import { ApplicationCommandOptions, ApplicationCommandOptionsAttachment, ApplicationCommandOptionsBoolean, ApplicationCommandOptionsChannel, ApplicationCommandOptionsChoice, ApplicationCommandOptionsInteger, ApplicationCommandOptionsMentionable, ApplicationCommandOptionsNumber, ApplicationCommandOptionsRole, ApplicationCommandOptionsString, ApplicationCommandOptionsSubCommand, ApplicationCommandOptionsSubCommandGroup, ApplicationCommandOptionsUser, ApplicationCommandOptionTypes, ChannelTypes } from "oceanic.js"; type TypeToOption<T extends ApplicationCommandOptionTypes> = T extends ApplicationCommandOptionTypes.SUB_COMMAND ? ApplicationCommandOptionsSubCommand : T extends ApplicationCommandOptionTypes.SUB_COMMAND_GROUP ? ApplicationCommandOptionsSubCommandGroup : T extends ApplicationCommandOptionTypes.STRING ? ApplicationCommandOptionsString : T extends ApplicationCommandOptionTypes.INTEGER ? ApplicationCommandOptionsInteger : T extends ApplicationCommandOptionTypes.BOOLEAN ? ApplicationCommandOptionsBoolean : T extends ApplicationCommandOptionTypes.USER ? ApplicationCommandOptionsUser : T extends ApplicationCommandOptionTypes.CHANNEL ? ApplicationCommandOptionsChannel : T extends ApplicationCommandOptionTypes.ROLE ? ApplicationCommandOptionsRole : T extends ApplicationCommandOptionTypes.MENTIONABLE ? ApplicationCommandOptionsMentionable : T extends ApplicationCommandOptionTypes.NUMBER ? ApplicationCommandOptionsNumber : T extends ApplicationCommandOptionTypes.ATTACHMENT ? ApplicationCommandOptionsAttachment : never; export default class ApplicationCommandOptionBuilder<T extends ApplicationCommandOptionTypes = ApplicationCommandOptionTypes> { autocomplete?: boolean; channelTypes?: Array<ChannelTypes>; choices: Array<ApplicationCommandOptionsChoice>; description: string; descriptionLocalizations?: Record<string, string>; max?: number; min?: number; name: string; nameLocalizations?: Record<string, string>; options: Array<ApplicationCommandOptions>; parent?: ApplicationCommandOptionBuilder<T>; required?: boolean; type: T; constructor(type: T, name: string); /** * Add a choice. * @param name The name of the choice. * @param value The value of the choice. * @param nameLocalizations A map of [locales](https://discord.com/developers/docs/reference#locales) to name localizations. */ addChoice(name: string, value: string | number, nameLocalizations?: Record<string, string>): this; /** * Add a description localization. * @param locale The [locale](https://discord.com/developers/docs/reference#locales) of the localization. * @param description The localized description. */ addDescriptionLocalization(locale: string, description: string): this; /** * Add a name localization. * @param locale The [locale](https://discord.com/developers/docs/reference#locales) of the localization. * @param name The localized name. */ addNameLocalization(locale: string, name: string): this; /** Add an option. */ addOption<O extends ApplicationCommandOptionTypes = ApplicationCommandOptionTypes>(option: ApplicationCommandOptionBuilder<O> | ApplicationCommandOptions): this; addOption<O extends ApplicationCommandOptionTypes = ApplicationCommandOptionTypes>(name: string, type: O, extra?: ((this: ApplicationCommandOptionBuilder<T>, option: ApplicationCommandOptionBuilder<O>) => void) | ApplicationCommandOptions): this; /** Toggle autocomplete for this option. */ setAutocomplete(value?: boolean): this; /** Set the allowed channel types for this option. */ setChannelTypes(types: Array<ChannelTypes>): this; /** Set the choices for this option. */ setChoices(choices: Array<ApplicationCommandOptionsChoice>): this; /** Set the description of this option. */ setDescription(description: string): this; /** * Set the description localizations of this option. * @param localizations A map of [locales](https://discord.com/developers/docs/reference#locales) to localized description strings. */ setDescriptionLocalizations(localizations: Record<string, string>): this; /** Set the min/max for this option. This applied to both `minValue`/`maxValue` and `minLength`/`maxLength`. */ setMinMax(min?: number, max?: number): this; /** Set the name of this option. */ setName(name: string): this; /** * Set the name localizations of this option. * @param localizations A map of [locales](https://discord.com/developers/docs/reference#locales) to localized name strings. */ setNameLocalizations(localizations: Record<string, string>): this; /** Toggle this option being required. */ setRequired(value?: boolean): this; /** Convert this command to JSON. */ toJSON(): TypeToOption<T>; } export {};