| 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([&bot](const dpp::slashcommand_t & event) { |
| 10 | /* Check which command they ran */ |
| 11 | if (event.command.get_command_name() == "blep") { |
| 12 | /* Fetch a parameter value from the command parameters */ |
| 13 | std::string animal = std::get<std::string>(event.get_parameter("animal")); |
| 14 | |
| 15 | /* Reply to the command. There is an overloaded version of this |
| 16 | * call that accepts a dpp::message so you can send embeds. |
| 17 | */ |
| 18 | event.reply(std::string("Blep! You chose") + animal); |
| 19 | } |
| 20 | }); |
| 21 | |
| 22 | bot.on_ready([&bot](const dpp::ready_t & event) { |
| 23 | if (dpp::run_once<struct register_bot_commands>()) { |
| 24 | /* Create a new global command on ready event */ |
| 25 | dpp::slashcommand newcommand("blep", "Send a random adorable animal photo", bot.me.id); |
| 26 | newcommand.add_option( |
| 27 | dpp::command_option(dpp::co_string, "animal", "The type of animal", true) |
| 28 | .add_choice(dpp::command_option_choice("Dog", std::string("animal_dog"))) |
| 29 | .add_choice(dpp::command_option_choice("Cat", std::string("animal_cat"))) |
| 30 | .add_choice(dpp::command_option_choice("Penguin", std::string("animal_penguin"))) |
| 31 | ); |
| 32 | |
| 33 | /* Register the command */ |
| 34 | bot.guild_command_create(newcommand, 857692897221033129); /* Replace this with the guild id you want */ |
| 35 | } |
| 36 | }); |
| 37 | |
| 38 | bot.start(dpp::st_wait); |
| 39 | |
| 40 | return 0; |
| 41 | } |
nothing calls this directly
no test coverage detected