This example demonstrates adding multiple buttons, receiving button clicks, and sending response messages.
#include <dpp/dpp.h>
int main() {
dpp::message msg(event.command.channel_id, "What is 5+5?");
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")
)
);
event.reply(msg);
}
});
event.reply(dpp::message("You got it right!").set_flags(dpp::m_ephemeral));
} else {
event.reply(dpp::message("Wrong! Try again.").set_flags(dpp::m_ephemeral));
}
});
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(
dpp::slashcommand(
"math",
"A quick maths question!", bot.me.id));
}
});
return 0;
}
This code will send a different message for correct and incorrect answers.