mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 11:03:30 +01:00
feat(builder): add max min length in string option (#8214)
This commit is contained in:
@@ -1,11 +1,43 @@
|
||||
import { s } from '@sapphire/shapeshift';
|
||||
import { APIApplicationCommandStringOption, ApplicationCommandOptionType } from 'discord-api-types/v10';
|
||||
import { mix } from 'ts-mixer';
|
||||
import { ApplicationCommandOptionBase } from '../mixins/ApplicationCommandOptionBase';
|
||||
import { ApplicationCommandOptionWithChoicesAndAutocompleteMixin } from '../mixins/ApplicationCommandOptionWithChoicesAndAutocompleteMixin';
|
||||
|
||||
const minLengthValidator = s.number.greaterThanOrEqual(0).lessThanOrEqual(6000);
|
||||
const maxLengthValidator = s.number.greaterThanOrEqual(1).lessThanOrEqual(6000);
|
||||
|
||||
@mix(ApplicationCommandOptionWithChoicesAndAutocompleteMixin)
|
||||
export class SlashCommandStringOption extends ApplicationCommandOptionBase {
|
||||
public readonly type = ApplicationCommandOptionType.String as const;
|
||||
public readonly max_length?: number;
|
||||
public readonly min_length?: number;
|
||||
|
||||
/**
|
||||
* Sets the maximum length of this string option.
|
||||
*
|
||||
* @param max - The maximum length this option can be
|
||||
*/
|
||||
public setMaxLength(max: number): this {
|
||||
maxLengthValidator.parse(max);
|
||||
|
||||
Reflect.set(this, 'max_length', max);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the minimum length of this string option.
|
||||
*
|
||||
* @param min - The minimum length this option can be
|
||||
*/
|
||||
public setMinLength(min: number): this {
|
||||
minLengthValidator.parse(min);
|
||||
|
||||
Reflect.set(this, 'min_length', min);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public toJSON(): APIApplicationCommandStringOption {
|
||||
this.runRequiredValidations();
|
||||
|
||||
Reference in New Issue
Block a user