components2

# Advanced Button Components

This example demonstrates adding multiple buttons, receiving button clicks, and sending response messages.

    #include<dpp/dpp.h>

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

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

    /*Theeventisfiredwhensomeoneissuesyourcommands*/
    bot.on_slashcommand([](constdpp::slashcommand_t&event){
    /*Checkwhichcommandtheyran*/
    if(event.command.get_command_name()=="math"){

    /*Createamessage*/
    dpp::messagemsg(event.command.channel_id,"Whatis5+5?");

    /*Addanactionrow,andthen3buttonswithintheactionrow.*/
    msg.add_component(
    dpp::component().add_component(
    dpp::component()
    .set_label("9")
    .set_style(dpp::cos_primary)
    .set_id("9")
    )
    .add_component(
    dpp::component()
    .set_label("10")
    .set_style(dpp::cos_primary)
    .set_id("10")
    )
    .add_component(
    dpp::component()
    .set_label("11")
    .set_style(dpp::cos_primary)
    .set_id("11")
    )
    );

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

    bot.on_button_click([](constdpp::button_click_t&event){
    if(event.custom_id=="10"){
    event.reply(dpp::message("Yougotitright!").set_flags(dpp::m_ephemeral));
    }else{
    event.reply(dpp::message("Wrong!Tryagain.").set_flags(dpp::m_ephemeral));
    }
    });

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

    bot.start(dpp::st_wait);

    return0;
    }

This code will send a different message for correct and incorrect answers.