Overview
Message components are interactive elements you can add to Discord messages. This library provides TypeScript types and enums for all Discord message components, making it easy to create rich, interactive experiences.Component Types
TheMessageComponentTypes enum includes all available component types:
Action Rows
Action Rows are required containers for interactive components. Most messages can have up to 5 action rows.Buttons
Buttons are clickable components that trigger interactions. There are several button styles available.Button Styles
Basic Button Example
Link Buttons
Link buttons don’t trigger interactions - they open URLs:Premium Buttons
Premium buttons are used for SKU purchases:Buttons with Emojis
Add emojis to buttons for visual appeal:Disabled Buttons
Handling Button Interactions
When a user clicks a button, Discord sends aMESSAGE_COMPONENT interaction:
Select Menus
Select menus let users choose from a list of options.String Select Menu
Text-based select menu with custom options:User Select Menu
Let users select Discord users:Role Select Menu
Let users select Discord roles:Mentionable Select Menu
Let users select both users and roles:Channel Select Menu
Let users select channels, optionally filtered by type:Available Channel Types
Handling Select Menu Interactions
Process select menu selections:Text Input (Modals)
Text inputs are used in modals for collecting user input:Handling Modal Submissions
Advanced Components
Container
Containers hold other components with optional styling:Separator
Add visual separation between content:Section
Sections display content with an optional accessory:Complete Example
Here’s a comprehensive example combining multiple component types:Best Practices
- Action Rows can contain up to 5 buttons or 1 select menu
- Messages can have up to 5 Action Rows
- Use descriptive
custom_idvalues to identify component interactions - Always handle component interactions with appropriate response types
Set
required: false on text inputs to make them optional in modals.Next Steps
Interactions
Learn more about handling interactions
Express Integration
Build a complete Express server with components