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()
{
.set_application_id(bot.me.id);
bot.guild_command_create(command, 857692897221033129);
});
dpp::command_interaction cmd_data = std::get<dpp::command_interaction>(event.command.data);
if (cmd_data.type == dpp::ctxm_user) {
if (cmd_data.name == "High Five") {
dpp::user user = event.command.resolved.users.begin()->second;
dpp::user author = event.command.usr;
event.reply(dpp::ir_channel_message_with_source, author.get_mention() + " slapped " + user.get_mention());
}
}
}
});
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.