D++ (DPP)
C++ Discord API Bot Library
Components V2

From March 2025 onwards Discord have released a new way to handle components in a Discord application/bot. The previous methods of working with components remain, and are accessible without any changes in D++. If you want to use the new style of components you may do so, which gives far greater control over how message containing images, buttons, sections etc are formatted.

Components are attached to any message or interaction reply, via the dpp::message::add_component() or dpp::message::add_component_v2() function. You must also be sure to set the flag dpp::m_using_components_v2 on the message to allow the new features.

When using components v2, the following limits apply which do not apply with components v1 or traditional embeds:

  • Setting the message content or embeds will not be allowed (components v2 replaces the functionality)
  • You can have a maximum of 10 top level components per message. The maximum number of nested components is 30.
  • Audio files are not supported at present
  • Text preview for text/plain files is not supported
  • URLs will not have embeds generated for them
  • The total length of the entire message, including all components within and the content of those components, is 4000 UTF-8 characters.

Here is a detailed example of how to create components v2 replies.

Warning
Please note that where you would use add_component() previously, you should use add_component_v2() (on component or message objects). This is because the v2 version will not automatically add action rows, which is a limitation which has been removed in version 2 but is still required for version 1.
#include <dpp/dpp.h>
int main() {
dpp::cluster bot("token");
bot.on_ready([&bot](const auto& event) {
if (dpp::run_once<struct boot_t>()) {
bot.global_bulk_command_create({ dpp::slashcommand("cats", "I love cats", bot.me.id) });
}
});
bot.on_button_click([](const dpp::button_click_t& event) {
event.reply("You declared your love for cats by clicking button id: " + event.custom_id);
});
/* This is a detailed example of using many different types of component. For a complete
* list of supported components, see the Discord developer documentation and the definition
* of dpp::component_type.
*/
bot.register_command("cats", [](const dpp::slashcommand_t& e) {
/* Remember to set the message flag for components v2 */
/* Reply with a container... */
.set_type(dpp::cot_container)
.set_accent(dpp::utility::rgb(255, 0, 0))
.set_spoiler(true)
.add_component_v2(
/* ...which contains a section... */
.set_type(dpp::cot_section)
.add_component_v2(
/* ...with text... */
.set_content("Click if you love cats")
)
.set_accessory(
/* ...and an accessory button to the right */
.set_type(dpp::cot_button)
.set_label("Click me")
.set_style(dpp::cos_danger)
.set_id("button")
)
)
/* ... with a large visible divider between... */
.set_type(dpp::cot_separator)
.set_spacing(dpp::sep_large)
.set_divider(true)
/* ... followed by a media gallery... */
.add_media_gallery_item(
/* ...containing one cat pic (obviously) */
.set_type(dpp::cot_thumbnail)
.set_description("A cat")
.set_thumbnail("https://www.catster.com/wp-content/uploads/2023/11/Beluga-Cat-e1714190563227.webp")
)
));
});
bot.start(dpp::st_wait);
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:89
Represents the component object. A component is a clickable button or drop down list within a discord...
Definition: message.h:487
Represents an application command, created by your bot either globally, or on a guild.
Definition: appcommand.h:1397
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
uint32_t DPP_EXPORT rgb(double red, double green, double blue)
Convert doubles to RGB for sending in embeds.
@ sep_large
Large separator.
Definition: message.h:472
@ m_using_components_v2
Message components vector contains v2 components.
Definition: message.h:1990
@ cos_danger
Red; danger.
Definition: message.h:233
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:72
@ cot_separator
Separator between sections or other components.
Definition: message.h:114
@ cot_button
Clickable button.
Definition: message.h:48
@ cot_media_gallery
Collection of media (images, videos)
Definition: message.h:102
@ cot_text_display
Simple text.
Definition: message.h:90
@ cot_section
Section.
Definition: message.h:84
@ cot_container
Container for other components.
Definition: message.h:125
@ cot_thumbnail
Image thumbnail, clickable to expand.
Definition: message.h:96
Click on button.
Definition: dispatcher.h:767
std::string custom_id
button custom id
Definition: dispatcher.h:777
void reply(command_completion_event_t callback=utility::log_error()) const
Acknowledge interaction without displaying a message to the user, for use with button and select menu...
Represents messages sent and received on Discord.
Definition: message.h:2340
message & add_component_v2(const component &c)
Add a component to a message.
message & set_flags(uint16_t f)
Set the flags.
User has issued a slash command.
Definition: dispatcher.h:759

There are many new component types, for a complete list see the definition of dpp::component_type

If you run the example program above, you will be shown a message containing your components:

D++ Library version 10.1.1D++ Library version 10.1.0D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0