What is @discordjs/builders?
@discordjs/builders is a utility package for building and formatting Discord API interactions, such as commands and embeds, in a structured and type-safe manner. It is part of the larger discord.js library ecosystem.
What are @discordjs/builders's main functionalities?
Slash Command Builder
The Slash Command Builder allows you to create and structure slash commands for your Discord bot. This example creates a simple 'ping' command that replies with 'Pong!'.
const { SlashCommandBuilder } = require('@discordjs/builders');
const command = new SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!');
console.log(command.toJSON());
Embed Builder
The Embed Builder helps you create rich embed messages with various properties like title, description, and color. This example creates a simple embed with a title, description, and green color.
const { EmbedBuilder } = require('@discordjs/builders');
const embed = new EmbedBuilder()
.setTitle('Sample Embed')
.setDescription('This is an example of an embed')
.setColor(0x00FF00);
console.log(embed.toJSON());
Button Builder
The Button Builder allows you to create interactive buttons for your Discord bot. This example creates a primary button with the label 'Click Me'.
const { ButtonBuilder, ButtonStyle } = require('@discordjs/builders');
const button = new ButtonBuilder()
.setCustomId('primary-button')
.setLabel('Click Me')
.setStyle(ButtonStyle.Primary);
console.log(button.toJSON());
Select Menu Builder
The Select Menu Builder helps you create dropdown menus for your Discord bot. This example creates a select menu with two options.
const { SelectMenuBuilder } = require('@discordjs/builders');
const selectMenu = new SelectMenuBuilder()
.setCustomId('select-menu')
.setPlaceholder('Choose an option')
.addOptions([
{ label: 'Option 1', value: 'option1' },
{ label: 'Option 2', value: 'option2' }
]);
console.log(selectMenu.toJSON());
Other packages similar to @discordjs/builders
discord.js
discord.js is a powerful library for interacting with the Discord API. It provides a comprehensive set of features for building Discord bots, including message handling, event handling, and more. While @discordjs/builders focuses on building and formatting interactions, discord.js offers a broader range of functionalities for bot development.
eris
Eris is another library for interacting with the Discord API. It is known for its performance and scalability, making it suitable for large bots. Eris provides similar functionalities to discord.js but with a different design philosophy. It does not have a dedicated builders package like @discordjs/builders, but it offers similar capabilities through its core library.
discord-interactions
discord-interactions is a library specifically designed for handling Discord interactions, such as slash commands and buttons. It provides utilities for validating and responding to interactions. While it offers similar functionalities to @discordjs/builders, it is more focused on the interaction aspect and does not provide the same level of integration with the broader Discord API.
About
@discordjs/builders
is a utility package for easily building Discord API payloads.
Installation
Node.js 18 or newer is required.
npm install @discordjs/builders
yarn add @discordjs/builders
pnpm add @discordjs/builders
Examples
You can find examples of how to use the builders in the Slash Command Builders examples.
Links
Contributing
Before creating an issue, please ensure that it hasn't already been reported/suggested, and double-check the
documentation.
See the contribution guide if you'd like to submit a PR.
Help
If you don't understand something in the documentation, you are experiencing problems, or you just need a gentle nudge in the right direction, please don't hesitate to join our official discord.js Server.