| 2 | #include <iostream> |
| 3 | |
| 4 | int main() { |
| 5 | dpp::cluster bot("token"); |
| 6 | |
| 7 | bot.on_log(dpp::utility::cout_logger()); |
| 8 | |
| 9 | /* Use the on_slashcommand event to look for commands */ |
| 10 | bot.on_slashcommand([&bot](const dpp::slashcommand_t & event) { |
| 11 | dpp::command_interaction cmd_data = event.command.get_command_interaction(); |
| 12 | |
| 13 | /* Check if the command is the image command. */ |
| 14 | if (event.command.get_command_name() == "image") { |
| 15 | /* Get the sub command */ |
| 16 | auto subcommand = cmd_data.options[0]; |
| 17 | /* Check if the subcommand is "dog" */ |
| 18 | if (subcommand.name == "dog") { |
| 19 | /* Checks if the subcommand has any options. */ |
| 20 | if (!subcommand.options.empty()) { |
| 21 | /* Get the user from the parameter */ |
| 22 | dpp::user user = event.command.get_resolved_user(subcommand.get_value<dpp::snowflake>(0)); |
| 23 | event.reply(user.get_mention() + " has now been turned into a dog."); |
| 24 | } else { |
| 25 | /* Reply if there were no options.. */ |
| 26 | event.reply("No user specified"); |
| 27 | } |
| 28 | } else if (subcommand.name == "cat") { /* Check if the subcommand is "cat". */ |
| 29 | /* Checks if the subcommand has any options. */ |
| 30 | if (!subcommand.options.empty()) { |
| 31 | /* Get the user from the parameter */ |
| 32 | dpp::user user = event.command.get_resolved_user(subcommand.get_value<dpp::snowflake>(0)); |
| 33 | event.reply(user.get_mention() + " has now been turned into a cat."); |
| 34 | } else { |
| 35 | /* Reply if there were no options.. */ |
| 36 | event.reply("No user specified"); |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | }); |
| 41 | |
| 42 | /* Executes on ready. */ |
| 43 | bot.on_ready([&bot](const dpp::ready_t & event) { |
| 44 | if (dpp::run_once<struct register_bot_commands>()) { |
| 45 | /* Define a slash command. */ |
| 46 | dpp::slashcommand image("image", "Send a specific image.", bot.me.id); |
| 47 | image.add_option( |
| 48 | /* Create a subcommand type option for "dog". */ |
| 49 | dpp::command_option(dpp::co_sub_command, "dog", "Send a picture of a dog.") |
| 50 | .add_option(dpp::command_option(dpp::co_user, "user", "User to turn into a dog.", false)) |
| 51 | ); |
| 52 | image.add_option( |
| 53 | /* Create another subcommand type option for "cat". */ |
| 54 | dpp::command_option(dpp::co_sub_command, "cat", "Send a picture of a cat.") |
| 55 | .add_option(dpp::command_option(dpp::co_user, "user", "User to turn into a cat.", false)) |
| 56 | ); |
| 57 | |
| 58 | /* Create command */ |
| 59 | bot.global_command_create(image); |
| 60 | } |
| 61 | }); |
nothing calls this directly
no test coverage detected