Skip to content

Commit bef3e2b

Browse files
authored
breaking: Added fallback to component receiving (#1516)
1 parent 1a0260a commit bef3e2b

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

docpages/example_code/modal_dialog_interactions.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,14 @@ int main() {
2424
.set_text_style(dpp::text_short)
2525
);
2626

27-
/* Add another text component in the next row, as required by Discord */
28-
modal.add_row();
27+
/* Add a channel selection */
2928
modal.add_component(
3029
dpp::component()
31-
.set_label("Type rammel")
32-
.set_id("field_id2")
33-
.set_type(dpp::cot_text)
34-
.set_placeholder("gumf")
35-
.set_min_length(1)
36-
.set_max_length(2000)
37-
.set_text_style(dpp::text_paragraph)
30+
.set_label("Select channel")
31+
.set_id("field_id2")
32+
.set_type(dpp::cot_channel_selectmenu)
3833
);
34+
3935

4036
/* Trigger the dialog box. All dialog boxes are ephemeral */
4137
event.dialog(modal);
@@ -44,13 +40,19 @@ int main() {
4440

4541
/* This event handles form submission for the modal dialog we create above */
4642
bot.on_form_submit([](const dpp::form_submit_t & event) {
47-
/* For this simple example, we know the first element of the first row ([0][0]) is value type string.
43+
/* For this simple example, we know the elements value type is string.
44+
* We also know the indices of each element.
4845
* In the real world, it may not be safe to make such assumptions!
4946
*/
50-
std::string v = std::get<std::string>(event.components[0].components[0].value);
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);
5149

5250
dpp::message m;
53-
m.set_content("You entered: " + v).set_flags(dpp::m_ephemeral);
51+
m.set_content(
52+
std::string("You entered '") + message_text +
53+
"', picked channel: <#" + channel_id + ">"
54+
)
55+
.set_flags(dpp::m_ephemeral);
5456

5557
/* Emit a reply. Form submission is still an interaction and must generate some form of reply! */
5658
event.reply(m);

src/dpp/events/interaction_create.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ std::string internal_handle_interaction(cluster* creator, uint16_t shard_id, jso
172172
if(c.contains("component")){
173173
fs.components.push_back(dpp::component().fill_from_json(&c["component"]));
174174
}
175+
else {
176+
fs.components.push_back(dpp::component().fill_from_json(&c));
177+
}
175178
}
176179
if (from_webhook) {
177180
fs.from_webhook = true;

0 commit comments

Comments
 (0)