subcommands

# Using Sub-Commands in Slash Commands

This demonstrates how to use sub-commands within slash commands. Also shown below is an example of how to get a "resolved" parameter without having to use the cache or an extra API call.

    #include<dpp/dpp.h>
    #include<iostream>

    intmain(){
    dpp::clusterbot("token");

    bot.on_log(dpp::utility::cout_logger());

    /*Usetheon_slashcommandeventtolookforcommands*/
    bot.on_slashcommand([](constdpp::slashcommand_t&event){
    dpp::command_interactioncmd_data=event.command.get_command_interaction();

    /*Checkifthecommandistheimagecommand.*/
    if(event.command.get_command_name()=="image"){
    /*Getthesubcommand*/
    autosubcommand=cmd_data.options[0];
    /*Checkifthesubcommandis"dog"*/
    if(subcommand.name=="dog"){
    /*Checksifthesubcommandhasanyoptions.*/
    if(!subcommand.options.empty()){
    /*Gettheuserfromtheparameter*/
    dpp::useruser=event.command.get_resolved_user(subcommand.get_value<dpp::snowflake>(0));
    event.reply(user.get_mention()+"hasnowbeenturnedintoadog.");
    }else{
    /*Replyiftherewerenooptions..*/
    event.reply("Nouserspecified");
    }
    }elseif(subcommand.name=="cat"){/*Checkifthesubcommandis"cat".*/
    /*Checksifthesubcommandhasanyoptions.*/
    if(!subcommand.options.empty()){
    /*Gettheuserfromtheparameter*/
    dpp::useruser=event.command.get_resolved_user(subcommand.get_value<dpp::snowflake>(0));
    event.reply(user.get_mention()+"hasnowbeenturnedintoacat.");
    }else{
    /*Replyiftherewerenooptions..*/
    event.reply("Nouserspecified");
    }
    }
    }
    });

    /*Executesonready.*/
    bot.on_ready([&bot](constdpp::ready_t&event){
    if(dpp::run_once<struct register_bot_commands>()){
    /*Defineaslashcommand.*/
    dpp::slashcommandimage("image","Sendaspecificimage.",bot.me.id);
    image.add_option(
    /*Createasubcommandtypeoptionfor"dog".*/
    dpp::command_option(dpp::co_sub_command,"dog","Sendapictureofadog.")
    .add_option(dpp::command_option(dpp::co_user,"user","Usertoturnintoadog.",false))
    );
    image.add_option(
    /*Createanothersubcommandtypeoptionfor"cat".*/
    dpp::command_option(dpp::co_sub_command,"cat","Sendapictureofacat.")
    .add_option(dpp::command_option(dpp::co_user,"user","Usertoturnintoacat.",false))
    );

    /*Createcommand*/
    bot.global_command_create(image);
    }
    });

    bot.start(dpp::st_wait);

    return0;
    }