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>
int main() {
dpp::interaction_modal_response modal("my_modal", "Please enter stuff");
modal.add_component(
dpp::component()
.set_label("Short type rammel")
.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)
);
modal.add_row();
modal.add_component(
dpp::component()
.set_label("Type rammel")
.set_id("field_id2")
.set_type(dpp::cot_text)
.set_placeholder("gumf")
.set_min_length(1)
.set_max_length(2000)
.set_text_style(dpp::text_paragraph)
);
event.dialog(modal);
}
});
std::string
v = std::get<std::string>(event.
components[0].components[0].value);
event.reply(m);
});
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(
dpp::slashcommand(
"dialog",
"Make a modal dialog box", bot.me.id));
}
});
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:80
std::string get_command_name() const
Get the command name for a command interaction.
Represents an application command, created by your bot either globally, or on a guild.
Definition: appcommand.h:1342
constexpr const char v[]
Definition: unicode_emoji.h:1982
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
@ m_ephemeral
This message is only visible to the user who invoked the Interaction.
Definition: message.h:1701
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:63
interaction command
command interaction
Definition: dispatcher.h:678
Represents messages sent and received on Discord.
Definition: message.h:2034
Session ready.
Definition: dispatcher.h:961
User has issued a slash command.
Definition: dispatcher.h:695
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: