@lunibee/builders
v0.4.0
Published
> Fluent, validated builders for embeds, components, modals, commands and attachments.
Readme
@lunibee/builders
Fluent, validated builders for embeds, components, modals, commands and attachments.
bun add @lunibee/buildersimport {
CreateEmbed,
CreateActionRow,
CreateButton,
ButtonType,
CreateStringSelect,
CreateSlashCommand,
} from "@lunibee/builders";
const embed = new CreateEmbed()
.setTitle("Welcome")
.setDescription("Pick a role below.")
.setColor(0xf5c542)
.addFields([{ name: "Server", value: "Lunibee" }]);
const buttons = new CreateActionRow().addComponents(
new CreateButton().setCustomId("yes").setLabel("Yes").setStyle(ButtonType.Success),
);
const menu = new CreateActionRow().addComponents(
new CreateStringSelect()
.setCustomId("role")
.addOptions({ label: "Developer", value: "dev" }),
);
const ping = new CreateSlashCommand()
.setName("ping")
.setDescription("Replies with pong")
.addStringOption((option) => option.setName("message").setDescription("Echo text"));
console.log(embed.toJSON(), buttons.toJSON(), menu.toJSON(), ping.toJSON());Builders
| Area | Builders |
|---|---|
| Embeds | CreateEmbed |
| Buttons & rows | CreateButton, CreateActionRow |
| Select menus | CreateStringSelect, CreateEntitySelect, CreateUserSelect, CreateRoleSelect, CreateChannelSelect, CreateMentionableSelect |
| Modals | CreateModal, CreateTextInput |
| Slash commands | CreateSlashCommand, CreateSubcommand, CreateSubcommandGroup, option builders |
| Context menus | CreateContextMenuCommand (setType(2 \| 3)), CreateUserCommand, CreateMessageCommand |
| Components V2 | CreateContainer, CreateSection, CreateTextDisplay, CreateMediaGallery, CreateFileComponent, CreateSeparator, CreateThumbnail |
| Files | CreateAttachment |
Every builder validates Discord's limits as you set values and serialises with toJSON().
What's new in 0.2.1
CreateModal.addTextInputs(...inputs)wraps each text input in its own row.componentsV2Message(components, options?)builds a Components V2 message with the required flag.CreateEmbedsetters (setTitle,setDescription,setURL,setThumbnail,setImage) clear the field withnull.TextInputTypeandComponentEnumare usable as types;CreateModal.toJSON()is typed with a requiredcustom_idandtitle.
What's new in 0.2.0
toJSON() validates whole components (required fields, value bounds, action-row rules, button field exclusivity); CreateButton.setSKUId() for premium buttons.
Docs: https://lunibee.js.org/core-concepts/builders/
