components

# Using Button Components

Discord's newest features support sending buttons alongside messages, which when clicked by the user trigger an interaction which is routed by D++ as an `on_button_click` event. To make use of this, use this code as in this example.

    #include<dpp/dpp.h>
    #include<dpp/unicode_emoji.h>

    intmain(){
    dpp::clusterbot("token");

    bot.on_log(dpp::utility::cout_logger());

    /*Theeventisfiredwhensomeoneissuesyourcommands*/
    bot.on_slashcommand([&bot](constdpp::slashcommand_t&event){
    /*Checkwhichcommandtheyran*/
    if(event.command.get_command_name()=="button"){
    /*Createamessage*/
    dpp::messagemsg(event.command.channel_id,"thistexthasabutton");

    /*Addanactionrow,andthenabuttonwithintheactionrow.*/
    msg.add_component(
    dpp::component().add_component(
    dpp::component()
    .set_label("Clickme!")
    .set_type(dpp::cot_button)
    .set_emoji(dpp::unicode_emoji::smile)
    .set_style(dpp::cos_danger)
    .set_id("myid")
    )
    );

    /*Replytotheuserwithourmessage.*/
    event.reply(msg);
    }
    });

    /*Whenauserclicksyourbutton,theon_button_clickeventwillfire,
    *containingthecustom_idyoudefinedinyourbutton.
    */
    bot.on_button_click([&bot](constdpp::button_click_t&event){
    /*Buttonclicksarestillinteractions,andmustberepliedtoinsomeformto
    *preventthe"thisinteractionhasfailed"messagefromDiscordtotheuser.
    */
    event.reply("Youclicked:"+event.custom_id);
    });

    bot.on_ready([&bot](constdpp::ready_t&event){
    if(dpp::run_once<struct register_bot_commands>()){
    /*Createandregisteracommandwhenthebotisready*/
    bot.global_command_create(dpp::slashcommand("button","Sendamessagewithabutton!",bot.me.id));
    }
    });

    bot.start(dpp::st_wait);

    return0;
    }

When the feature is functioning, the code below will produce buttons on the reply message like in the image below: