modal-dialog-interactions

# Modals

Modal dialog interactions are a new Discord API feature that allow you to have pop-up windows which prompt the user to input information. Once the user has filled in this information, your program will receive an `on_form_submit` event which will contain the data which was input. You must use a slash command interaction response to submit your modal form data to Discord, via the `on_slashcommand` event. From here calling the `dialog` method of the `interaction_create_t` event object will trigger the dialog to appear.

Each dialog box may have up to five rows of input fields. The example below demonstrates a simple setup with just one text input:

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

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

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

    bot.on_slashcommand([&bot](constdpp::slashcommand_t&event){
    /*Checkforour/dialogcommand*/
    if(event.command.get_command_name()=="dialog"){
    /*Instantiateaninteraction_modal_responseobject*/
    dpp::interaction_modal_responsemodal("my_modal","Pleaseenterstuff");

    /*Addatextcomponent*/
    modal.add_component(
    dpp::component()
    .set_label("Shorttyperammel")
    .set_id("field_id")
    .set_type(dpp::cot_text)
    .set_placeholder("gumd")
    .set_min_length(5)
    .set_max_length(50)
    .set_text_style(dpp::text_short)
    );

    /*Addachannelselection*/
    modal.add_component(
    dpp::component()
    .set_label("Selectchannel")
    .set_id("field_id2")
    .set_type(dpp::cot_channel_selectmenu)
    );

    /*Triggerthedialogbox.Alldialogboxesareephemeral*/
    event.dialog(modal);
    }
    });

    /*Thiseventhandlesformsubmissionforthemodaldialogwecreateabove*/
    bot.on_form_submit([](constdpp::form_submit_t&event){
    /*Forthissimpleexample,weknowtheelementsvaluetypeisstring.
    *Wealsoknowtheindicesofeachelement.
    *Intherealworld,itmaynotbesafetomakesuchassumptions!
    */
    std::stringmessage_text=std::get<std::string>(event.components[0].value);
    std::stringchannel_id=std::get<std::string>(event.components[1].value);

    dpp::messagem;
    m.set_content(
    std::string("Youentered'")+message_text+
    "',pickedchannel:<#"+channel_id+">"
    )
    .set_flags(dpp::m_ephemeral);

    /*Emitareply.Formsubmissionisstillaninteractionandmustgeneratesomeformofreply!*/
    event.reply(m);
    });

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

    /*Startbot*/
    bot.start(dpp::st_wait);

    return0;
    }

If you compile and run this program and wait for the global command to register, typing `/dialog` will present you with a dialog box like the one below: