Saltearse al contenido

Opciones de un comando

Las opciones en Discord tienen por obligación una descripción. Además, en todas las opciones podemos establecer si será requerida y una función para moldear el valor.

Tipos de opciones

Los posibles tipos de opciones en un comando son los siguientes:

Texto

import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createStringOption<R extends boolean, C extends SeyfertChoice<string>[] = SeyfertChoice<string>[], VC = never>(data: SeyfertStringOption<C, R, VC>): {
readonly type: ApplicationCommandOptionType.String;
readonly required?: R | undefined;
readonly choices?: C | undefined;
readonly value?: ValueCallback<ApplicationCommandOptionType.String, C, VC> | undefined;
readonly description: string;
readonly description_localizations?: APIApplicationCommandBasicOption["description_localizations"];
readonly name_localizations?: APIApplicationCommandBasicOption["name_localizations"];
readonly locales?: {
name?: FlatObjectKeys<DefaultLocale>;
description?: FlatObjectKeys<DefaultLocale>;
};
readonly autocomplete?: AutocompleteCallback;
readonly onAutocompleteError?: OnAutocompleteErrorCallback;
readonly min_length?: number;
readonly max_length?: number;
}
createStringOption
,
class Command
Command
} from 'seyfert';
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
({
normal: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_length?: number;
}
normal
:
createStringOption<boolean, SeyfertChoice<string>[], any>(data: SeyfertStringOption<SeyfertChoice<string>[], boolean, any>): {
readonly type: ApplicationCommandOptionType.String;
... 10 more ...;
readonly max_length?: number;
}
createStringOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: '',
}),
/// Opciones fijas
choices: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: [...] | undefined;
... 8 more ...;
readonly max_length?: number;
}
choices
:
createStringOption<boolean, [{
readonly name: "The best library";
readonly value: "seyfert";
}, {
readonly name: "An odd stuff";
readonly value: "meowdb";
}], any>(data: SeyfertStringOption<[{
readonly name: "The best library";
readonly value: "seyfert";
}, {
readonly name: "An odd stuff";
readonly value: "meowdb";
}], boolean, any>): {
...;
}
createStringOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: '',
SeyfertBaseChoiceableOption<ApplicationCommandOptionType.String, [{ readonly name: "The best library"; readonly value: "seyfert"; }, { readonly name: "An odd stuff"; readonly value: "meowdb"; }], boolean, any>.choices?: [{
readonly name: "The best library";
readonly value: "seyfert";
}, {
readonly name: "An odd stuff";
readonly value: "meowdb";
}] | undefined
choices
: [
{
name: "The best library"
name
: 'The best library',
value: "seyfert"
value
: 'seyfert' },
{
name: "An odd stuff"
name
: 'An odd stuff',
value: "meowdb"
value
: 'meowdb' },
] as
type const = [{
readonly name: "The best library";
readonly value: "seyfert";
}, {
readonly name: "An odd stuff";
readonly value: "meowdb";
}]
const
,
}),
/// Autocompletado
autocomplete: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_length?: number;
}
autocomplete
:
createStringOption<boolean, SeyfertChoice<string>[], any>(data: SeyfertStringOption<SeyfertChoice<string>[], boolean, any>): {
readonly type: ApplicationCommandOptionType.String;
... 10 more ...;
readonly max_length?: number;
}
createStringOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: '',
autocomplete?: AutocompleteCallback | undefined
autocomplete
: (
interaction: AutocompleteInteraction<boolean>
interaction
) => {
// aquí la lógica
const
const select: string[]
select
= ['bugs', 'actions', 'random'];
const
const focus: string
focus
=
interaction: AutocompleteInteraction<boolean>
interaction
.
AutocompleteInteraction<boolean>.getInput(): string
getInput
();
return
interaction: AutocompleteInteraction<boolean>
interaction
.
AutocompleteInteraction<boolean>.respond(choices: APICommandAutocompleteInteractionResponseCallbackData["choices"]): Promise<undefined>
respond
(
const select: string[]
select
.
Array<string>.filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[] (+1 overload)

Returns the elements of an array that meet the condition specified in a callback function.

@parampredicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

@paramthisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

filter
((
ch: string
ch
) =>
ch: string
ch
.
String.includes(searchString: string, position?: number): boolean

Returns true if searchString appears as a substring of the result of converting this object to a String, at one or more positions that are greater than or equal to position; otherwise, returns false.

@paramsearchString search string

@paramposition If position is undefined, 0 is assumed, so as to search all of the String.

includes
(
const focus: string
focus
))
.
Array<string>.map<{
name: string;
value: string;
}>(callbackfn: (value: string, index: number, array: string[]) => {
name: string;
value: string;
}, thisArg?: any): {
name: string;
value: string;
}[]

Calls a defined callback function on each element of an array, and returns an array that contains the results.

@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

map
((
ch: string
ch
) => ({
name: string
name
:
ch: string
ch
,
value: string
value
:
ch: string
ch
}))
);
},
}),
/// Límites de carácteres
limitLength: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_length?: number;
}
limitLength
:
createStringOption<boolean, SeyfertChoice<string>[], any>(data: SeyfertStringOption<SeyfertChoice<string>[], boolean, any>): {
readonly type: ApplicationCommandOptionType.String;
... 10 more ...;
readonly max_length?: number;
}
createStringOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: '',
max_length?: number | undefined
max_length
: 500,
min_length?: number | undefined
min_length
: 200,
}),
})
class
class Ping
Ping
extends
class Command
Command
{}
Ejemplo de autocompletado de TypeScript
import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createStringOption<R extends boolean, C extends SeyfertChoice<string>[] = SeyfertChoice<string>[], VC = never>(data: SeyfertStringOption<C, R, VC>): {
readonly type: ApplicationCommandOptionType.String;
readonly required?: R | undefined;
readonly choices?: C | undefined;
readonly value?: ValueCallback<ApplicationCommandOptionType.String, C, VC> | undefined;
readonly description: string;
readonly description_localizations?: APIApplicationCommandBasicOption["description_localizations"];
readonly name_localizations?: APIApplicationCommandBasicOption["name_localizations"];
readonly locales?: {
name?: FlatObjectKeys<DefaultLocale>;
description?: FlatObjectKeys<DefaultLocale>;
};
readonly autocomplete?: AutocompleteCallback;
readonly onAutocompleteError?: OnAutocompleteErrorCallback;
readonly min_length?: number;
readonly max_length?: number;
}
createStringOption
,
class Command
Command
,
class CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
CommandContext
} from 'seyfert';
const
const options: {
best: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: [...] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}
options
= {
/// Opciones fijas
best: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: [...] | undefined;
... 8 more ...;
readonly max_length?: number;
}
best
:
createStringOption<boolean, [{
readonly name: "The best library";
readonly value: "seyfert";
}, {
readonly name: "An odd stuff";
readonly value: "meowdb";
}], never>(data: SeyfertStringOption<[{
readonly name: "The best library";
readonly value: "seyfert";
}, {
readonly name: "An odd stuff";
readonly value: "meowdb";
}], boolean, never>): {
...;
}
createStringOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: '',
SeyfertBaseChoiceableOption<ApplicationCommandOptionType.String, [{ readonly name: "The best library"; readonly value: "seyfert"; }, { readonly name: "An odd stuff"; readonly value: "meowdb"; }], boolean, never>.choices?: [{
readonly name: "The best library";
readonly value: "seyfert";
}, {
readonly name: "An odd stuff";
readonly value: "meowdb";
}] | undefined
choices
: [
{
name: "The best library"
name
: 'The best library',
value: "seyfert"
value
: 'seyfert' },
{
name: "An odd stuff"
name
: 'An odd stuff',
value: "meowdb"
value
: 'meowdb' },
] as
type const = [{
readonly name: "The best library";
readonly value: "seyfert";
}, {
readonly name: "An odd stuff";
readonly value: "meowdb";
}]
const
,
}),
};
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
(
const options: {
best: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: [...] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}
options
)
class
class Ping
Ping
extends
class Command
Command
{
async
Ping.run(ctx: CommandContext<typeof options>): Promise<void>
run
(
ctx: CommandContext<{
best: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: [...] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}, never>
ctx
:
class CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
CommandContext
<typeof
const options: {
best: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: [...] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}
options
>) {
ctx: CommandContext<{
best: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: [...] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}, never>
ctx
.
CommandContext<{ best: { readonly type: ApplicationCommandOptionType.String; readonly required?: boolean | undefined; readonly choices?: [...] | undefined; ... 8 more ...; readonly max_length?: number; }; }, never>.options: ContextOptions<{
best: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: [...] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}>
options
.best;
best?: "seyfert" | "meowdb" | undefined
}
}

Números enteros

import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createIntegerOption<R extends boolean, C extends SeyfertChoice<number>[] = SeyfertChoice<number>[], VC = never>(data: SeyfertIntegerOption<C, R, VC>): {
readonly type: ApplicationCommandOptionType.Integer;
readonly required?: R | undefined;
readonly choices?: C | undefined;
readonly value?: ValueCallback<ApplicationCommandOptionType.Integer, C, VC> | undefined;
readonly description: string;
readonly description_localizations?: APIApplicationCommandBasicOption["description_localizations"];
readonly name_localizations?: APIApplicationCommandBasicOption["name_localizations"];
readonly locales?: {
name?: FlatObjectKeys<DefaultLocale>;
description?: FlatObjectKeys<DefaultLocale>;
};
readonly autocomplete?: AutocompleteCallback;
readonly onAutocompleteError?: OnAutocompleteErrorCallback;
readonly min_value?: number;
readonly max_value?: number;
}
createIntegerOption
,
class Command
Command
} from 'seyfert';
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
({
normal: {
readonly type: ApplicationCommandOptionType.Integer;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_value?: number;
}
normal
:
createIntegerOption<boolean, SeyfertChoice<number>[], any>(data: SeyfertIntegerOption<SeyfertChoice<number>[], boolean, any>): {
readonly type: ApplicationCommandOptionType.Integer;
... 10 more ...;
readonly max_value?: number;
}
createIntegerOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: '',
}),
/// Opciones fijas
choices: {
readonly type: ApplicationCommandOptionType.Integer;
readonly required?: boolean | undefined;
readonly choices?: {
...;
}[] | undefined;
... 8 more ...;
readonly max_value?: number;
}
choices
:
createIntegerOption<boolean, {
name: string;
value: number;
}[], any>(data: SeyfertIntegerOption<{
name: string;
value: number;
}[], boolean, any>): {
readonly type: ApplicationCommandOptionType.Integer;
... 10 more ...;
readonly max_value?: number;
}
createIntegerOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: '',
SeyfertBaseChoiceableOption<ApplicationCommandOptionType.Integer, { name: string; value: number; }[], boolean, any>.choices?: {
name: string;
value: number;
}[] | undefined
choices
: [
{
name: string
name
: 'seyfert',
value: number
value
: 1 },
{
name: string
name
: 'potocuit',
value: number
value
: 2 },
{
name: string
name
: 'biscuit',
value: number
value
: 3 }
]
}),
/// Autocompletado
autocomplete: {
readonly type: ApplicationCommandOptionType.Integer;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_value?: number;
}
autocomplete
:
createIntegerOption<boolean, SeyfertChoice<number>[], any>(data: SeyfertIntegerOption<SeyfertChoice<number>[], boolean, any>): {
readonly type: ApplicationCommandOptionType.Integer;
... 10 more ...;
readonly max_value?: number;
}
createIntegerOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: '',
autocomplete?: AutocompleteCallback | undefined
autocomplete
: (
interaction: AutocompleteInteraction<boolean>
interaction
) => {
const
const select: string[]
select
= ['1651611', '4616165156549', '15616416515616'];
const
const focus: string
focus
=
interaction: AutocompleteInteraction<boolean>
interaction
.
AutocompleteInteraction<boolean>.getInput(): string
getInput
();
return
interaction: AutocompleteInteraction<boolean>
interaction
.
AutocompleteInteraction<boolean>.respond(choices: APICommandAutocompleteInteractionResponseCallbackData["choices"]): Promise<undefined>
respond
(
const select: string[]
select
.
Array<string>.filter(predicate: (value: string, index: number, array: string[]) => unknown, thisArg?: any): string[] (+1 overload)

Returns the elements of an array that meet the condition specified in a callback function.

@parampredicate A function that accepts up to three arguments. The filter method calls the predicate function one time for each element in the array.

@paramthisArg An object to which the this keyword can refer in the predicate function. If thisArg is omitted, undefined is used as the this value.

filter
((
ch: string
ch
) =>
ch: string
ch
.
String.includes(searchString: string, position?: number): boolean

Returns true if searchString appears as a substring of the result of converting this object to a String, at one or more positions that are greater than or equal to position; otherwise, returns false.

@paramsearchString search string

@paramposition If position is undefined, 0 is assumed, so as to search all of the String.

includes
(
const focus: string
focus
))
.
Array<string>.map<{
name: string;
value: number;
}>(callbackfn: (value: string, index: number, array: string[]) => {
name: string;
value: number;
}, thisArg?: any): {
name: string;
value: number;
}[]

Calls a defined callback function on each element of an array, and returns an array that contains the results.

@paramcallbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array.

@paramthisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value.

map
((
ch: string
ch
) => ({
name: string
name
:
ch: string
ch
,
value: number
value
:
function parseInt(string: string, radix?: number): number

Converts a string to an integer.

@paramstring A string to convert into a number.

@paramradix A value between 2 and 36 that specifies the base of the number in string. If this argument is not supplied, strings with a prefix of '0x' are considered hexadecimal. All other strings are considered decimal.

parseInt
(
ch: string
ch
) }))
);
}
}),
/// Límites de valores
limitValue: {
readonly type: ApplicationCommandOptionType.Integer;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_value?: number;
}
limitValue
:
createIntegerOption<boolean, SeyfertChoice<number>[], any>(data: SeyfertIntegerOption<SeyfertChoice<number>[], boolean, any>): {
readonly type: ApplicationCommandOptionType.Integer;
... 10 more ...;
readonly max_value?: number;
}
createIntegerOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: '',
max_value?: number | undefined
max_value
: 500,
min_value?: number | undefined
min_value
: 200
})
})
class
class Ping
Ping
extends
class Command
Command
{}

Número

import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createNumberOption<R extends boolean, C extends SeyfertChoice<number>[] = SeyfertChoice<number>[], VC = never>(data: SeyfertNumberOption<C, R, VC>): {
readonly type: ApplicationCommandOptionType.Number;
readonly required?: R | undefined;
readonly choices?: C | undefined;
readonly value?: ValueCallback<ApplicationCommandOptionType.Number, C, VC> | undefined;
readonly description: string;
readonly description_localizations?: APIApplicationCommandBasicOption["description_localizations"];
readonly name_localizations?: APIApplicationCommandBasicOption["name_localizations"];
readonly locales?: {
name?: FlatObjectKeys<DefaultLocale>;
description?: FlatObjectKeys<DefaultLocale>;
};
readonly autocomplete?: AutocompleteCallback;
readonly onAutocompleteError?: OnAutocompleteErrorCallback;
readonly min_value?: number;
readonly max_value?: number;
}
createNumberOption
,
class Command
Command
} from 'seyfert';
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
({
normal: {
readonly type: ApplicationCommandOptionType.Number;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_value?: number;
}
normal
:
createNumberOption<boolean, SeyfertChoice<number>[], any>(data: SeyfertNumberOption<SeyfertChoice<number>[], boolean, any>): {
readonly type: ApplicationCommandOptionType.Number;
... 10 more ...;
readonly max_value?: number;
}
createNumberOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: '',
}),
// Aplica lo mismo que el anterior (integer/enteros), pero para todos los números incluyendo decimales
})
class
class Ping
Ping
extends
class Command
Command
{}

Canales

import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createChannelOption<R extends boolean, C extends keyof SeyfertChannelMap = keyof SeyfertChannelMap, VC = never>(data: SeyfertChannelOption<C, R, VC>): {
readonly type: ApplicationCommandOptionType.Channel;
readonly required?: R | undefined;
readonly value?: ValueCallback<ApplicationCommandOptionType.Channel, C, VC> | undefined;
readonly description: string;
readonly description_localizations?: APIApplicationCommandBasicOption["description_localizations"];
readonly name_localizations?: APIApplicationCommandBasicOption["name_localizations"];
readonly locales?: {
name?: FlatObjectKeys<DefaultLocale>;
description?: FlatObjectKeys<DefaultLocale>;
};
readonly channel_types?: C[] | undefined;
}
createChannelOption
,
class Command
Command
} from 'seyfert';
import { ChannelType } from 'seyfert/lib/types';
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
({
channel: {
readonly type: ApplicationCommandOptionType.Channel;
readonly required?: boolean | undefined;
readonly value?: ValueCallback<...> | undefined;
... 4 more ...;
readonly channel_types?: (keyof SeyfertChannelMap)[] | undefined;
}
channel
:
createChannelOption<boolean, keyof SeyfertChannelMap, any>(data: SeyfertChannelOption<keyof SeyfertChannelMap, boolean, any>): {
...;
}
createChannelOption
({
description: string
description
: '',
}),
/// Tipo específico de canal
channelTypes: {
readonly type: ApplicationCommandOptionType.Channel;
readonly required?: boolean | undefined;
readonly value?: ValueCallback<...> | undefined;
... 4 more ...;
readonly channel_types?: ChannelType.GuildVoice[] | undefined;
}
channelTypes
:
createChannelOption<boolean, ChannelType.GuildVoice, any>(data: SeyfertChannelOption<ChannelType.GuildVoice, boolean, any>): {
readonly type: ApplicationCommandOptionType.Channel;
... 6 more ...;
readonly channel_types?: ChannelType.GuildVoice[] | undefined;
}
createChannelOption
({
description: string
description
: 'This is a limited channel option',
channel_types?: ChannelType.GuildVoice[] | undefined
channel_types
: [ChannelType.
function (enum member) ChannelType.GuildVoice = 2

A voice channel within a guild

GuildVoice
]
})
})
class
class Ping
Ping
extends
class Command
Command
{}

Booleanos

import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createBooleanOption<R extends boolean, T extends SeyfertBooleanOption<R> = SeyfertBooleanOption<R>>(data: T): T & {
readonly type: ApplicationCommandOptionType.Boolean;
}
createBooleanOption
,
class Command
Command
} from 'seyfert';
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
({
bool: {
description: string;
required: true;
} & {
readonly type: ApplicationCommandOptionType.Boolean;
}
bool
:
createBooleanOption<boolean, {
description: string;
required: true;
}>(data: {
description: string;
required: true;
}): {
description: string;
required: true;
} & {
readonly type: ApplicationCommandOptionType.Boolean;
}
createBooleanOption
({
description: string
description
: 'This is a boolean option',
required: true
required
: true
})
})
class
class Ping
Ping
extends
class Command
Command
{}

Usuarios

import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createUserOption<R extends boolean, T extends SeyfertUserOption<R> = SeyfertUserOption<R>>(data: T): T & {
readonly type: ApplicationCommandOptionType.User;
}
createUserOption
,
class Command
Command
} from 'seyfert';
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
({
user: {
description: string;
required: true;
} & {
readonly type: ApplicationCommandOptionType.User;
}
user
:
createUserOption<boolean, {
description: string;
required: true;
}>(data: {
description: string;
required: true;
}): {
description: string;
required: true;
} & {
readonly type: ApplicationCommandOptionType.User;
}
createUserOption
({
description: string
description
: 'This is a user option',
required: true
required
: true
})
})
class
class Ping
Ping
extends
class Command
Command
{}

Roles

import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createRoleOption<R extends boolean, T extends SeyfertRoleOption<R> = SeyfertRoleOption<R>>(data: T): T & {
readonly type: ApplicationCommandOptionType.Role;
}
createRoleOption
,
class Command
Command
} from 'seyfert';
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
({
role: {
description: string;
required: true;
} & {
readonly type: ApplicationCommandOptionType.Role;
}
role
:
createRoleOption<boolean, {
description: string;
required: true;
}>(data: {
description: string;
required: true;
}): {
description: string;
required: true;
} & {
readonly type: ApplicationCommandOptionType.Role;
}
createRoleOption
({
description: string
description
: 'This is a role option',
required: true
required
: true
})
})
class
class Ping
Ping
extends
class Command
Command
{}

Mencionables

import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createMentionableOption<R extends boolean, T extends SeyfertMentionableOption<R> = SeyfertMentionableOption<R>>(data: T): T & {
readonly type: ApplicationCommandOptionType.Mentionable;
}
createMentionableOption
,
class Command
Command
} from 'seyfert';
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
({
mentionable: {
description: string;
required: true;
} & {
readonly type: ApplicationCommandOptionType.Mentionable;
}
mentionable
:
createMentionableOption<boolean, {
description: string;
required: true;
}>(data: {
description: string;
required: true;
}): {
description: string;
required: true;
} & {
readonly type: ApplicationCommandOptionType.Mentionable;
}
createMentionableOption
({
description: string
description
: 'This is a mentionable option',
required: true
required
: true
})
})
class
class Ping
Ping
extends
class Command
Command
{}

Archivos

import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createAttachmentOption<R extends boolean, T extends SeyfertAttachmentOption<R> = SeyfertAttachmentOption<R>>(data: T): T & {
readonly type: ApplicationCommandOptionType.Attachment;
}
createAttachmentOption
,
class Command
Command
} from 'seyfert';
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
({
attachment: {
description: string;
required: true;
} & {
readonly type: ApplicationCommandOptionType.Attachment;
}
attachment
:
createAttachmentOption<boolean, {
description: string;
required: true;
}>(data: {
description: string;
required: true;
}): {
description: string;
required: true;
} & {
readonly type: ApplicationCommandOptionType.Attachment;
}
createAttachmentOption
({
description: string
description
: 'This is a attachment option',
required: true
required
: true
})
})
class
class Ping
Ping
extends
class Command
Command
{}

Moldeando el valor

Podemos transformar el valor de cualquier opción en algo más, para eso utilizamos el método value que recibe como parámetros el valor del dato y dos funciones: ok y fail.

import {
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
,
function createStringOption<R extends boolean, C extends SeyfertChoice<string>[] = SeyfertChoice<string>[], VC = never>(data: SeyfertStringOption<C, R, VC>): {
readonly type: ApplicationCommandOptionType.String;
readonly required?: R | undefined;
readonly choices?: C | undefined;
readonly value?: ValueCallback<ApplicationCommandOptionType.String, C, VC> | undefined;
readonly description: string;
readonly description_localizations?: APIApplicationCommandBasicOption["description_localizations"];
readonly name_localizations?: APIApplicationCommandBasicOption["name_localizations"];
readonly locales?: {
name?: FlatObjectKeys<DefaultLocale>;
description?: FlatObjectKeys<DefaultLocale>;
};
readonly autocomplete?: AutocompleteCallback;
readonly onAutocompleteError?: OnAutocompleteErrorCallback;
readonly min_length?: number;
readonly max_length?: number;
}
createStringOption
,
class Command
Command
} from 'seyfert';
import type {
type OKFunction<T> = (value: T) => void
OKFunction
,
class CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
CommandContext
} from 'seyfert';
const
const options: {
url: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}
options
= {
url: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_length?: number;
}
url
:
createStringOption<boolean, SeyfertChoice<string>[], URL>(data: SeyfertStringOption<SeyfertChoice<string>[], boolean, URL>): {
readonly type: ApplicationCommandOptionType.String;
... 10 more ...;
readonly max_length?: number;
}
createStringOption
({
SeyfertBaseChoiceableOption<T extends keyof ReturnOptionsTypes, C = T extends ChoiceableTypes ? SeyfertChoice<ChoiceableValues[T]>[] : never, R = boolean, VC = never>.description: string
description
: 'how to be a gamer',
SeyfertBaseChoiceableOption<ApplicationCommandOptionType.String, SeyfertChoice<string>[], boolean, URL>.value?: ValueCallback<ApplicationCommandOptionType.String, SeyfertChoice<string>[], URL> | undefined
value
(
data: {
context: CommandContext;
value: string;
}
data
,
ok: OKFunction<URL>
ok
:
type OKFunction<T> = (value: T) => void
OKFunction
<
interface URL

URL class is a global reference for import { URL } from 'url' https://nodejs.org/api/url.html#the-whatwg-url-api

@sincev10.0.0

URL
>,
fail: StopFunction
fail
) {
if (
function isUrl(url: string): boolean
isUrl
(
data: {
context: CommandContext;
value: string;
}
data
.
value: string
value
)) return
ok: (value: URL) => void
ok
(new
var URL: new (input: string | {
toString: () => string;
}, base?: string | URL) => URL

URL class is a global reference for import { URL } from 'url' https://nodejs.org/api/url.html#the-whatwg-url-api

@sincev10.0.0

URL
(
data: {
context: CommandContext;
value: string;
}
data
.
value: string
value
));
fail: (error: string) => void
fail
('expected a valid url');
}
})
}
@
function Options(options: (new () => SubCommand)[] | OptionsRecord): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
options: SubCommand[] | CommandOption[];
};
} & T
Options
(
const options: {
url: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}
options
)
class
class Ping
Ping
extends
class Command
Command
{
Ping.run(ctx: CommandContext<typeof options>): void
run
(
ctx: CommandContext<{
url: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}, never>
ctx
:
class CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
CommandContext
<typeof
const options: {
url: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}
options
>) {
ctx: CommandContext<{
url: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}, never>
ctx
.
CommandContext<{ url: { readonly type: ApplicationCommandOptionType.String; readonly required?: boolean | undefined; readonly choices?: SeyfertChoice<...>[] | undefined; ... 8 more ...; readonly max_length?: number; }; }, never>.options: ContextOptions<{
url: {
readonly type: ApplicationCommandOptionType.String;
readonly required?: boolean | undefined;
readonly choices?: SeyfertChoice<...>[] | undefined;
... 8 more ...;
readonly max_length?: number;
};
}>
options
.url;
url?: URL | undefined
}
}

Ahora el tipo de dato que recibe el valor del comando es URL, si no es así se lanzará un error.

En crear su primer comando se ofrece un ejemplo detallado para obtener autocompletado.