Building components
Components are built with a builder, which is a JavaScript class, which represents it. Within this builder you can customize the component so it’s either text or color.
There are diffrent types of components’ builders with diffrent customization but all have a common property: the custom Id. A unique identifier which is used for handling the interactions of the component.
ActionRow
All the builders are sent within an ActionRow
. Each message can contain a maxium of 5 actions row.
Here is how we create a basic ActionRow:
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();
Building each component
Now we are going to build each type of component and set it within an ActionRow:
An ActionRow shouldn’t contain more than 5 buttons.
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('first-button') .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('First Button');
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]);
An ActionRow shouldn’t contain more than one select menu.
There are diffrent types of select menus: StringSelectMenu
, UserSelectMenu
, RoleSelectMenu
, ChannelSelectMenu
and MentionableSelectMenu
.
We are going to make diffrent action rows for each select menu.
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('string-menu') .SelectMenu<APISelectMenuComponent, ComponentInteraction<boolean, APIMessageComponentInteraction>>.setPlaceholder(placeholder: string): StringSelectMenu
Sets the placeholder text for the select menu.
setPlaceholder('Select an string option') .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('Option 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('Option 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('user-menu') .SelectMenu<APIUserSelectComponent, UserSelectMenuInteraction>.setPlaceholder(placeholder: string): UserSelectMenu
Sets the placeholder text for the select menu.
setPlaceholder('Select an user') //user id's .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('role-menu') .SelectMenu<APIRoleSelectComponent, RoleSelectMenuInteraction>.setPlaceholder(placeholder: string): RoleSelectMenu
Sets the placeholder text for the select menu.
setPlaceholder('Select a role') //role id's .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('channel-menu') .SelectMenu<APIChannelSelectComponent, ChannelSelectMenuInteraction>.setPlaceholder(placeholder: string): ChannelSelectMenu
Sets the placeholder text for the select menu.
setPlaceholder('Select a channel') //channel id's .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('mentionable-menu') .SelectMenu<APIMentionableSelectComponent, MentionableSelectMenuInteraction>.setPlaceholder(placeholder: string): MentionableSelectMenu
Sets the placeholder text for the select menu.
setPlaceholder('Select a mentionable') //mentionable id's (role or user) .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]);
Sending the components
After creating the components you have to send the ActionRow into the components field. You can check example below:
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: 'Show the ping with 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) { // average latency between shards 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: `The ping is \`${const ping: number
ping}\``, ResolverProps.components?: APIActionRowComponent<APIMessageActionRowComponent>[] | ActionRow<BuilderComponents>[] | undefined
components: [const row: ActionRow<BuilderComponents>
row] }); }}