Skip to content

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.

@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
();

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 { 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
('first-button')
.
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
('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.

@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
]);

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 { 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.

@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
: `The ping is \`${
const ping: number
ping
}\``,
ResolverProps.components?: APIActionRowComponent<APIMessageActionRowComponent>[] | ActionRow<BuilderComponents>[] | undefined
components
: [
const row: ActionRow<BuilderComponents>
row
]
});
}
}