context-menu

# Context Menus

Context menus are application commands that appear on the context menu (right click or tap) of users or messages to perform context-specific actions. They can be created using dpp::slashcommand. Once you create a context menu, try right-clicking either a user or message to see it in your server!

This example sets the command as the type dpp::ctxm_user which can only be used by right clicking on a user. To make it appear on a message, you'll want to switch the type to dpp::ctxm_message and listen for the `on_message_context_menu` (dpp::message_context_menu_t) event.

The following example shows how to create and handle user context menus for message context menus, read the notice above.

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

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

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

    /*Usetheon_user_context_menueventtolookforusercontextmenuactions*/
    bot.on_user_context_menu([](constdpp::user_context_menu_t&event){

    /*checkifthecontextmenunameisHighFive*/
    if(event.command.get_command_name()=="highfive"){
    dpp::useruser=event.get_user();//theuserwhothecommandhasbeenissuedon
    dpp::userauthor=event.command.get_issuing_user();//theuserwhoclickedonthecontextmenu
    event.reply(author.get_mention()+"slapped"+user.get_mention());
    }
    });

    bot.on_ready([&bot](constdpp::ready_t&event){
    if(dpp::run_once<struct register_bot_commands>()){
    /*Createthecommand*/
    dpp::slashcommandcommand;
    command.set_name("HighFive")
    .set_application_id(bot.me.id)
    .set_type(dpp::ctxm_user);

    /*Registerthecommand*/
    bot.guild_command_create(command,857692897221033129);/*Replacethiswiththeguildidyouwant*/
    }
    });

    /*Startbot*/
    bot.start(dpp::st_wait);

    return0;
    }

It registers a guild command that can be called by right-clicking a user and clicking on the created menu.