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>
int main() {
auto subcommand = cmd_data.options[0];
if (subcommand.name == "dog") {
if (!subcommand.options.empty()) {
dpp::user user = event.command.get_resolved_user(subcommand.get_value<dpp::snowflake>(0));
event.reply(user.get_mention() + " has now been turned into a dog.");
} else {
event.reply("No user specified");
}
} else if (subcommand.name == "cat") {
if (!subcommand.options.empty()) {
dpp::user user = event.command.get_resolved_user(subcommand.get_value<dpp::snowflake>(0));
event.reply(user.get_mention() + " has now been turned into a cat.");
} else {
event.reply("No user specified");
}
}
}
});
if (dpp::run_once<struct register_bot_commands>()) {
image.add_option(
);
image.add_option(
);
bot.global_command_create(image);
}
});
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:80
std::string get_command_name() const
Get the command name for a command interaction.
Represents an application command, created by your bot either globally, or on a guild.
Definition: appcommand.h:1339
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
@ co_sub_command
A sub-command.
Definition: appcommand.h:54
@ co_user
A user snowflake id.
Definition: appcommand.h:79
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:63
Details of a command within an interaction. This subobject represents the application command associa...
Definition: appcommand.h:803
Each command option is a command line parameter. It can have a type (see dpp::command_option_type),...
Definition: appcommand.h:203
interaction command
command interaction
Definition: dispatcher.h:677
Session ready.
Definition: dispatcher.h:960
User has issued a slash command.
Definition: dispatcher.h:694