| 1 | #include <dpp/dpp.h> |
| 2 | |
| 3 | int main() { |
| 4 | dpp::cluster bot("token"); |
| 5 | |
| 6 | bot.on_log(dpp::utility::cout_logger()); |
| 7 | |
| 8 | /* The event is fired when someone issues your commands */ |
| 9 | bot.on_slashcommand([](const dpp::slashcommand_t& event) { |
| 10 | /* Check which command they ran */ |
| 11 | if (event.command.get_command_name() == "math") { |
| 12 | |
| 13 | /* Create a message */ |
| 14 | dpp::message msg(event.command.channel_id, "What is 5+5?"); |
| 15 | |
| 16 | /* Add an action row, and then 3 buttons within the action row. */ |
| 17 | msg.add_component( |
| 18 | dpp::component().add_component( |
| 19 | dpp::component() |
| 20 | .set_label("9") |
| 21 | .set_style(dpp::cos_primary) |
| 22 | .set_id("9") |
| 23 | ) |
| 24 | .add_component( |
| 25 | dpp::component() |
| 26 | .set_label("10") |
| 27 | .set_style(dpp::cos_primary) |
| 28 | .set_id("10") |
| 29 | ) |
| 30 | .add_component( |
| 31 | dpp::component() |
| 32 | .set_label("11") |
| 33 | .set_style(dpp::cos_primary) |
| 34 | .set_id("11") |
| 35 | ) |
| 36 | ); |
| 37 | |
| 38 | /* Reply to the user with our message. */ |
| 39 | event.reply(msg); |
| 40 | } |
| 41 | }); |
| 42 | |
| 43 | bot.on_button_click([](const dpp::button_click_t& event) { |
| 44 | if (event.custom_id == "10") { |
| 45 | event.reply(dpp::message("You got it right!").set_flags(dpp::m_ephemeral)); |
| 46 | } else { |
| 47 | event.reply(dpp::message("Wrong! Try again.").set_flags(dpp::m_ephemeral)); |
| 48 | } |
| 49 | }); |
| 50 | |
| 51 | bot.on_ready([&bot](const dpp::ready_t& event) { |
| 52 | if (dpp::run_once<struct register_bot_commands>()) { |
| 53 | /* Create and register a command when the bot is ready */ |
| 54 | bot.global_command_create(dpp::slashcommand("math", "A quick maths question!", bot.me.id)); |
| 55 | } |
| 56 | }); |
| 57 | |
| 58 | bot.start(dpp::st_wait); |
| 59 | |
| 60 | return 0; |
| 61 | } |