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.
ActionRow()
.ActionRow<BuilderComponents>.setComponents(component: BuilderComponents[]): ActionRow<BuilderComponents>
Sets the components of the Action Row.
setComponents([])
.ActionRow<BuilderComponents>.addComponents(...component: RestOrArray<BuilderComponents>): ActionRow<BuilderComponents>
Adds one or more components to the Action Row.
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 { enum ButtonStyle
ButtonStyle } from 'seyfert/lib/types';
const const button: Button
button = new new Button(data?: Partial<APIButtonComponent>): Button
Creates a new Button instance.
Button() .Button.setCustomId(id: string): Button
Sets the custom ID for the button.
setCustomId('primer-boton') .Button.setStyle(style: ButtonStyle): Button
setStyle(enum ButtonStyle
ButtonStyle.function (enum member) ButtonStyle.Primary = 1
Primary) .Button.setLabel(label: string): Button
Sets the label for the button.
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.
ActionRow<class Button
Represents a button component.
Button>().ActionRow<Button>.setComponents(component: (ButtonLink | ButtonID)[]): ActionRow<Button>
Sets the components of the Action Row.
setComponents([const button: Button
button]);
Una ActionRow no debe contener más de un menú select.
Existen diferentes tipos de menús select: StringSelectMenu
, UserSelectMenu
, RoleSelectMenu
, ChannelSelectMenu
y MentionableSelectMenu
.
Vamos a crear diferentes filas de acción para cada menú select.
import { class ActionRow<T extends BuilderComponents>
Represents an Action Row component in a message.
ActionRow, class StringSelectMenu
Represents a Select Menu for selecting string options.
StringSelectMenu, class StringSelectOption
Represents an individual option for a string select menu.
StringSelectOption, class UserSelectMenu
Represents a Select Menu for selecting users.
UserSelectMenu, class RoleSelectMenu
Represents a Select Menu for selecting roles.
RoleSelectMenu, class ChannelSelectMenu
Represents a Select Menu for selecting channels.
ChannelSelectMenu, class MentionableSelectMenu
Represents a Select Menu for selecting mentionable entities.
MentionableSelectMenu} from 'seyfert';
const const stringMenu: StringSelectMenu
stringMenu = new new StringSelectMenu(data?: Partial<APIStringSelectComponent>): StringSelectMenu
Represents a Select Menu for selecting string options.
StringSelectMenu() .SelectMenu<APISelectMenuComponent, ComponentInteraction<boolean, APIMessageComponentInteraction>>.setCustomId(id: string): StringSelectMenu
Sets the custom ID for the select menu.
setCustomId('menu-de-cadenas') .SelectMenu<APISelectMenuComponent, ComponentInteraction<boolean, APIMessageComponentInteraction>>.setPlaceholder(placeholder: string): StringSelectMenu
Sets the placeholder text for the select menu.
setPlaceholder('Selecciona una opción de cadena') .StringSelectMenu.addOption(...options: RestOrArray<StringSelectOption>): StringSelectMenu
Adds options to the string select menu.
addOption( new new StringSelectOption(data?: Partial<APISelectMenuOption>): StringSelectOption
Represents an individual option for a string select menu.
StringSelectOption().StringSelectOption.setLabel(label: string): StringSelectOption
Sets the label for the option.
label - The label for the option.
setLabel('Opción 1').StringSelectOption.setValue(value: string): StringSelectOption
Sets the value for the option.
value - The value for the option.
setValue('1'), new new StringSelectOption(data?: Partial<APISelectMenuOption>): StringSelectOption
Represents an individual option for a string select menu.
StringSelectOption().StringSelectOption.setLabel(label: string): StringSelectOption
Sets the label for the option.
label - The label for the option.
setLabel('Opción 2').StringSelectOption.setValue(value: string): StringSelectOption
Sets the value for the option.
value - The value for the option.
setValue('2') );
const const stringRow: ActionRow<StringSelectMenu>
stringRow = new new ActionRow<StringSelectMenu>({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>): ActionRow<...>
Creates a new instance of the ActionRow class.
ActionRow<class StringSelectMenu
Represents a Select Menu for selecting string options.
StringSelectMenu>().ActionRow<StringSelectMenu>.setComponents(component: StringSelectMenu[]): ActionRow<StringSelectMenu>
Sets the components of the Action Row.
setComponents([const stringMenu: StringSelectMenu
stringMenu]);
const const userMenu: UserSelectMenu
userMenu = new new UserSelectMenu(data?: Partial<APIUserSelectComponent>): UserSelectMenu
Represents a Select Menu for selecting users.
UserSelectMenu() .SelectMenu<APIUserSelectComponent, UserSelectMenuInteraction>.setCustomId(id: string): UserSelectMenu
Sets the custom ID for the select menu.
setCustomId('menu-de-usuarios') .SelectMenu<APIUserSelectComponent, UserSelectMenuInteraction>.setPlaceholder(placeholder: string): UserSelectMenu
Sets the placeholder text for the select menu.
setPlaceholder('Selecciona un usuario') //id de usuarios .UserSelectMenu.setDefaultUsers(...users: RestOrArray<string>): UserSelectMenu
Sets the default selected users for the select menu.
setDefaultUsers('123456789', '987654321');
const const userRow: ActionRow<UserSelectMenu>
userRow = new new ActionRow<UserSelectMenu>({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>): ActionRow<...>
Creates a new instance of the ActionRow class.
ActionRow<class UserSelectMenu
Represents a Select Menu for selecting users.
UserSelectMenu>().ActionRow<UserSelectMenu>.setComponents(component: UserSelectMenu[]): ActionRow<UserSelectMenu>
Sets the components of the Action Row.
setComponents([const userMenu: UserSelectMenu
userMenu]);
const const roleMenu: RoleSelectMenu
roleMenu = new new RoleSelectMenu(data?: Partial<APIRoleSelectComponent>): RoleSelectMenu
Represents a Select Menu for selecting roles.
RoleSelectMenu() .SelectMenu<APIRoleSelectComponent, RoleSelectMenuInteraction>.setCustomId(id: string): RoleSelectMenu
Sets the custom ID for the select menu.
setCustomId('menu-de-roles') .SelectMenu<APIRoleSelectComponent, RoleSelectMenuInteraction>.setPlaceholder(placeholder: string): RoleSelectMenu
Sets the placeholder text for the select menu.
setPlaceholder('Selecciona un rol') //id de roles .RoleSelectMenu.setDefaultRoles(...roles: RestOrArray<string>): RoleSelectMenu
Sets the default selected roles for the select menu.
setDefaultRoles('123456789', '987654321');
const const roleRow: ActionRow<RoleSelectMenu>
roleRow = new new ActionRow<RoleSelectMenu>({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>): ActionRow<...>
Creates a new instance of the ActionRow class.
ActionRow<class RoleSelectMenu
Represents a Select Menu for selecting roles.
RoleSelectMenu>().ActionRow<RoleSelectMenu>.setComponents(component: RoleSelectMenu[]): ActionRow<RoleSelectMenu>
Sets the components of the Action Row.
setComponents([const roleMenu: RoleSelectMenu
roleMenu]);
const const channelMenu: ChannelSelectMenu
channelMenu = new new ChannelSelectMenu(data?: Partial<APIChannelSelectComponent>): ChannelSelectMenu
Represents a Select Menu for selecting channels.
ChannelSelectMenu() .SelectMenu<APIChannelSelectComponent, ChannelSelectMenuInteraction>.setCustomId(id: string): ChannelSelectMenu
Sets the custom ID for the select menu.
setCustomId('menu-de-canales') .SelectMenu<APIChannelSelectComponent, ChannelSelectMenuInteraction>.setPlaceholder(placeholder: string): ChannelSelectMenu
Sets the placeholder text for the select menu.
setPlaceholder('Selecciona un canal') //id de canales .ChannelSelectMenu.setDefaultChannels(...channels: RestOrArray<string>): ChannelSelectMenu
Sets the default selected channels for the select menu.
setDefaultChannels('123456789', '987654321');
const const channelRow: ActionRow<ChannelSelectMenu>
channelRow = new new ActionRow<ChannelSelectMenu>({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>): ActionRow<...>
Creates a new instance of the ActionRow class.
ActionRow<class ChannelSelectMenu
Represents a Select Menu for selecting channels.
ChannelSelectMenu>().ActionRow<ChannelSelectMenu>.setComponents(component: ChannelSelectMenu[]): ActionRow<ChannelSelectMenu>
Sets the components of the Action Row.
setComponents([const channelMenu: ChannelSelectMenu
channelMenu]);
const const mentionableMenu: MentionableSelectMenu
mentionableMenu = new new MentionableSelectMenu(data?: Partial<APIMentionableSelectComponent>): MentionableSelectMenu
Represents a Select Menu for selecting mentionable entities.
MentionableSelectMenu() .SelectMenu<APIMentionableSelectComponent, MentionableSelectMenuInteraction>.setCustomId(id: string): MentionableSelectMenu
Sets the custom ID for the select menu.
setCustomId('menu-de-mencionables') .SelectMenu<APIMentionableSelectComponent, MentionableSelectMenuInteraction>.setPlaceholder(placeholder: string): MentionableSelectMenu
Sets the placeholder text for the select menu.
setPlaceholder('Selecciona un mencionable') //id de mencionables (rol o usuario) .MentionableSelectMenu.setDefaultMentionables(...mentionables: RestOrArray<MentionableDefaultElement>): MentionableSelectMenu
Sets the default selected roles or users for the select menu.
setDefaultMentionables( { type: "Role" | "User"
type: 'User', id: string
id: '123456789' }, { type: "Role" | "User"
type: 'Role', id: string
id: '987654321' } );
const const mentionableRow: ActionRow<MentionableSelectMenu>
mentionableRow = new new ActionRow<MentionableSelectMenu>({ components, ...data }?: Partial<APIActionRowComponent<APIActionRowComponentTypes>>): ActionRow<...>
Creates a new instance of the ActionRow class.
ActionRow<class MentionableSelectMenu
Represents a Select Menu for selecting mentionable entities.
MentionableSelectMenu>().ActionRow<MentionableSelectMenu>.setComponents(component: MentionableSelectMenu[]): ActionRow<MentionableSelectMenu>
Sets the components of the Action Row.
setComponents([const mentionableMenu: MentionableSelectMenu
mentionableMenu]);
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 { enum ButtonStyle
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.
ActionRow() .ActionRow<BuilderComponents>.setComponents(component: BuilderComponents[]): ActionRow<BuilderComponents>
Sets the components of the Action Row.
setComponents([ new new Button(data?: Partial<APIButtonComponent>): Button
Creates a new Button instance.
Button().Button.setCustomId(id: string): Button
Sets the custom ID for the button.
setCustomId('pingbtn').Button.setLabel(label: string): Button
Sets the label for the button.
setLabel(`Ping: ${const ping: number
ping}`).Button.setStyle(style: ButtonStyle): Button
setStyle(enum ButtonStyle
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] }); }}