D++ (DPP)
C++ Discord API Bot Library
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!

The following example shows how to create and handle user context menus.

#include <dpp/dpp.h>
#include <iostream>
int main()
{
dpp::cluster bot("token");
bot.on_ready([&bot](const dpp::ready_t &event) {
/* Define a slash command */
command.set_name("High Five")
.set_type(dpp::ctxm_user)
.set_application_id(bot.me.id);
/* Register the command */
bot.guild_command_create(command, 857692897221033129); // you need to put your guild-id in here
});
/* Use the on_interaction_create event to look for application commands */
bot.on_interaction_create([&](const dpp::interaction_create_t &event) {
dpp::command_interaction cmd_data = std::get<dpp::command_interaction>(event.command.data);
/* check if the command is a user context menu action */
if (cmd_data.type == dpp::ctxm_user) {
/* check if the context menu name is High Five */
if (cmd_data.name == "High Five") {
dpp::user user = event.command.resolved.users.begin()->second; // the user who the command has been issued on
dpp::user author = event.command.usr; // the user who clicked on the context menu
event.reply(dpp::ir_channel_message_with_source, author.get_mention() + " slapped " + user.get_mention());
}
}
}
});
/* Start bot */
bot.start(false);
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:392
uint8_t type
the type of interaction
Definition: appcommand.h:589
Represents an application command, created by your bot either globally, or on a guild.
Definition: appcommand.h:727
slashcommand & set_name(const std::string &n)
Set the name of the command.
@ ctxm_user
Add command to user context menu.
Definition: appcommand.h:497
@ it_application_command
application command (slash command)
Definition: appcommand.h:485
Create interaction.
Definition: dispatcher.h:270
interaction command
command interaction
Definition: dispatcher.h:362
Session ready.
Definition: dispatcher.h:568

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

D++ Library version 10.0.35D++ Library version 10.0.34D++ Library version 10.0.33D++ Library version 10.0.32D++ Library version 10.0.31D++ Library version 10.0.30D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ Library version 9.0.13D++ Library version 9.0.12D++ Library version 9.0.11D++ Library version 9.0.10D++ Library version 9.0.9D++ Library version 9.0.8D++ Library version 9.0.7D++ Library version 9.0.6D++ Library version 9.0.5D++ Library version 9.0.4D++ Library version 9.0.3D++ Library version 9.0.2D++ Library version 9.0.1D++ Library version 9.0.0D++ Library version 1.0.2D++ Library version 1.0.1D++ Library version 1.0.0