Saltearse al contenido

Componentes de construcción

Los componentes se construyen con un generador, que es una clase de JavaScript, la cual lo representa. Dentro de este generador, puedes personalizar el componente para que sea de texto o color.

Existen diferentes tipos de generadores de componentes con distintas personalizaciones, pero todos tienen una propiedad común: el Id personalizado. Un identificador único que se utiliza para gestionar las interacciones del componente.

ActionRow

Todos los generadores se envían dentro de una ActionRow. Cada mensaje puede contener un máximo de 5 filas de acción.

Aquí se muestra cómo crear una ActionRow básica:

import {
class ActionRow<T extends BuilderComponents>

Represents an Action Row component in a message.

ActionRow
} from 'seyfert';
const
const row: ActionRow<BuilderComponents>
row
= new
new ActionRow<BuilderComponents>({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>): ActionRow<...>

Creates a new instance of the ActionRow class.

@paramdata - Optional data to initialize the Action Row.

@example const actionRow = new ActionRow({ components: [buttonRawJSON] });

ActionRow
()
.
ActionRow<BuilderComponents>.setComponents(component: BuilderComponents[]): ActionRow<BuilderComponents>

Sets the components of the Action Row.

@paramcomponent - The components to set.

@returnsThe updated Action Row instance.

@example actionRow.setComponents([buttonComponent1, buttonComponent2]);

setComponents
([])
.
ActionRow<BuilderComponents>.addComponents(...component: RestOrArray<BuilderComponents>): ActionRow<BuilderComponents>

Adds one or more components to the Action Row.

@paramcomponent - The component(s) to add.

@returnsThe updated Action Row instance.

@example actionRow.addComponents(buttonComponent); actionRow.addComponents(buttonComponent1, buttonComponent2); actionRow.addComponents([buttonComponent1, buttonComponent2]);

addComponents
();

Construyendo cada componente

Ahora vamos a construir cada tipo de componente y establecerlo dentro de una ActionRow:

Una ActionRow no debe contener más de 5 botones.

import {
class ActionRow<T extends BuilderComponents>

Represents an Action Row component in a message.

ActionRow
,
class Button

Represents a button component.

Button
} from 'seyfert';
import { ButtonStyle } from 'seyfert/lib/types';
const
const button: Button
button
= new
new Button(data?: Partial<APIButtonComponent>): Button

Creates a new Button instance.

@paramdata - The initial data for the button.

Button
()
.
Button.setCustomId(id: string): Button

Sets the custom ID for the button.

@paramid - The custom ID to set.

@returnsThe modified Button instance.

setCustomId
('primer-boton')
.
Button.setStyle(style: ButtonStyle): Button
setStyle
(ButtonStyle.
function (enum member) ButtonStyle.Primary = 1
Primary
)
.
Button.setLabel(label: string): Button

Sets the label for the button.

@paramlabel - The label to set.

@returnsThe modified Button instance.

setLabel
('Primer Botón');
const
const row: ActionRow<Button>
row
= new
new ActionRow<Button>({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>): ActionRow<...>

Creates a new instance of the ActionRow class.

@paramdata - Optional data to initialize the Action Row.

@example const actionRow = new ActionRow({ components: [buttonRawJSON] });

ActionRow
<
class Button

Represents a button component.

Button
>().
ActionRow<Button>.setComponents(component: (ButtonLink | ButtonID)[]): ActionRow<Button>

Sets the components of the Action Row.

@paramcomponent - The components to set.

@returnsThe updated Action Row instance.

@example actionRow.setComponents([buttonComponent1, buttonComponent2]);

setComponents
([
const button: Button
button
]);

Enviando los componentes

Después de crear los componentes, debes enviar la ActionRow al campo de componentes. Puedes ver un ejemplo a continuación:

import {
function Declare(declare: CommandDeclareOptions): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
name: string;
nsfw: boolean | undefined;
props: ExtraProps | undefined;
contexts: InteractionContextType[];
integrationTypes: ApplicationIntegrationType[];
defaultMemberPermissions: bigint | undefined;
botPermissions: bigint | undefined;
description: string;
type: ApplicationCommandType;
guildId?: string[];
ignore?: IgnoreCommand;
aliases?: string[];
handler?: EntryPointCommandHandlerType;
};
} & T
Declare
,
class Command
Command
, type
class CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
CommandContext
,
class ActionRow<T extends BuilderComponents>

Represents an Action Row component in a message.

ActionRow
,
class Button

Represents a button component.

Button
} from 'seyfert';
import { ButtonStyle } from 'seyfert/lib/types';
@
function Declare(declare: CommandDeclareOptions): <T extends {
new (...args: any[]): object;
}>(target: T) => {
new (...args: any[]): {
name: string;
nsfw: boolean | undefined;
props: ExtraProps | undefined;
contexts: InteractionContextType[];
integrationTypes: ApplicationIntegrationType[];
defaultMemberPermissions: bigint | undefined;
botPermissions: bigint | undefined;
description: string;
type: ApplicationCommandType;
guildId?: string[];
ignore?: IgnoreCommand;
aliases?: string[];
handler?: EntryPointCommandHandlerType;
};
} & T
Declare
({
name: string
name
: 'ping',
description: string
description
: 'Muestra el ping con Discord'
})
export default class
class PingCommand
PingCommand
extends
class Command
Command
{
async
PingCommand.run(ctx: CommandContext): Promise<void>
run
(
ctx: CommandContext<{}, never>
ctx
:
class CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
interface CommandContext<T extends OptionsRecord = {}, M extends keyof RegisteredMiddlewares = never>
CommandContext
) {
// latencia promedio entre fragmentos
const
const ping: number
ping
=
ctx: CommandContext<{}, never>
ctx
.
CommandContext<{}, never>.client: UsingClient
client
.
Client<true>.gateway: ShardManager
gateway
.
ShardManager.latency: number
latency
;
const
const row: ActionRow<BuilderComponents>
row
= new
new ActionRow<BuilderComponents>({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>): ActionRow<...>

Creates a new instance of the ActionRow class.

@paramdata - Optional data to initialize the Action Row.

@example const actionRow = new ActionRow({ components: [buttonRawJSON] });

ActionRow
()
.
ActionRow<BuilderComponents>.setComponents(component: BuilderComponents[]): ActionRow<BuilderComponents>

Sets the components of the Action Row.

@paramcomponent - The components to set.

@returnsThe updated Action Row instance.

@example actionRow.setComponents([buttonComponent1, buttonComponent2]);

setComponents
([
new
new Button(data?: Partial<APIButtonComponent>): Button

Creates a new Button instance.

@paramdata - The initial data for the button.

Button
().
Button.setCustomId(id: string): Button

Sets the custom ID for the button.

@paramid - The custom ID to set.

@returnsThe modified Button instance.

setCustomId
('pingbtn').
Button.setLabel(label: string): Button

Sets the label for the button.

@paramlabel - The label to set.

@returnsThe modified Button instance.

setLabel
(`Ping: ${
const ping: number
ping
}`).
Button.setStyle(style: ButtonStyle): Button
setStyle
(ButtonStyle.
function (enum member) ButtonStyle.Primary = 1
Primary
)
])
await
ctx: CommandContext<{}, never>
ctx
.
CommandContext<{}, never>.write<false>(body: InteractionCreateBodyRequest, withResponse?: false | undefined): Promise<void | WebhookMessage>
write
({
content?: string | undefined

The message contents (up to 2000 characters)

content
: `El ping es \`${
const ping: number
ping
}\``,
ResolverProps.components?: APIActionRowComponent<APIMessageActionRowComponent>[] | ActionRow<BuilderComponents>[] | undefined
components
: [
const row: ActionRow<BuilderComponents>
row
]
});
}
}