MCPcopy Create free account
hub / github.com/brainboxdotcc/DPP / main

Function main

docpages/example_code/modal_dialog_interactions.cpp:4–72  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <iostream>
3
4int main() {
5 dpp::cluster bot("token");
6
7 bot.on_log(dpp::utility::cout_logger());
8
9 bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) {
10 /* Check for our /dialog command */
11 if (event.command.get_command_name() == "dialog") {
12 /* Instantiate an interaction_modal_response object */
13 dpp::interaction_modal_response modal("my_modal", "Please enter stuff");
14
15 /* Add a text component */
16 modal.add_component(
17 dpp::component()
18 .set_label("Short type rammel")
19 .set_id("field_id")
20 .set_type(dpp::cot_text)
21 .set_placeholder("gumd")
22 .set_min_length(5)
23 .set_max_length(50)
24 .set_text_style(dpp::text_short)
25 );
26
27 /* Add a channel selection */
28 modal.add_component(
29 dpp::component()
30 .set_label("Select channel")
31 .set_id("field_id2")
32 .set_type(dpp::cot_channel_selectmenu)
33 );
34
35
36 /* Trigger the dialog box. All dialog boxes are ephemeral */
37 event.dialog(modal);
38 }
39 });
40
41 /* This event handles form submission for the modal dialog we create above */
42 bot.on_form_submit([](const dpp::form_submit_t & event) {
43 /* For this simple example, we know the elements value type is string.
44 * We also know the indices of each element.
45 * In the real world, it may not be safe to make such assumptions!
46 */
47 std::string message_text = std::get<std::string>(event.components[0].value);
48 std::string channel_id = std::get<std::string>(event.components[1].value);
49
50 dpp::message m;
51 m.set_content(
52 std::string("You entered '") + message_text +
53 "', picked channel: <#" + channel_id + ">"
54 )
55 .set_flags(dpp::m_ephemeral);
56
57 /* Emit a reply. Form submission is still an interaction and must generate some form of reply! */
58 event.reply(m);
59 });
60
61 bot.on_ready([&bot](const dpp::ready_t & event) {

Callers

nothing calls this directly

Calls 7

cout_loggerFunction · 0.85
stringFunction · 0.85
get_command_nameMethod · 0.80
dialogMethod · 0.80
global_command_createMethod · 0.80
startMethod · 0.80
replyMethod · 0.45

Tested by

no test coverage detected