| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
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!

Note
  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>
int main()
{
dpp::cluster bot("token");
bot.on_log(dpp::utility::cout_logger());
/* Use the on_user_context_menu event to look for user context menu actions */
bot.on_user_context_menu([](const dpp::user_context_menu_t& event) {
/* check if the context menu name is High Five */
if (event.command.get_command_name() == "high five") {
dpp::user user = event.get_user(); // the user who the command has been issued on
dpp::user author = event.command.get_issuing_user(); // the user who clicked on the context menu
event.reply(author.get_mention() + " slapped " + user.get_mention());
}
});
bot.on_ready([&bot](const dpp::ready_t& event) {
if (dpp::run_once<struct register_bot_commands>()) {
/* Create the command */
dpp::slashcommand command;
command.set_name("High Five")
.set_application_id(bot.me.id)
.set_type(dpp::ctxm_user);
/* Register the command */
bot.guild_command_create(command, 857692897221033129); /* Replace this with the guild id you want */
}
});
/* Start bot */
bot.start(dpp::st_wait);
return 0;
}
dpp::cluster
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition cluster.h:89
dpp::interaction::get_command_name
std::string get_command_name() const
Get the command name for a command interaction.
dpp::slashcommand
Represents an application command, created by your bot either globally, or on a guild.
Definition appcommand.h:1449
dpp::slashcommand::set_application_id
slashcommand & set_application_id(snowflake i)
Set the application id of the command.
dpp::slashcommand::set_type
slashcommand & set_type(slashcommand_contextmenu_type _type)
Set the type of the slash command (only for context menu entries).
dpp::slashcommand::set_name
slashcommand & set_name(const std::string &n)
Set the name of the command.
dpp::user
Represents a user on discord. May or may not be a member of a dpp::guild.
Definition user.h:163
dpp::user::get_mention
static std::string get_mention(const snowflake &id)
Create a mentionable user.
dpp::utility::cout_logger
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
dpp::ctxm_user
@ ctxm_user
A slashcommand that goes in the user context menu.
Definition appcommand.h:861
dpp::run_once
auto run_once()
Run some code within an if() statement only once.
Definition once.h:41
dpp::st_wait
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition cluster.h:72
dpp::interaction_create_t::command
interaction command
command interaction
Definition dispatcher.h:789
dpp::ready_t
Session ready.
Definition dispatcher.h:1072

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

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0