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()) {
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()) {
event.reply(user.
get_mention() +
" has now been turned into a cat.");
} else {
event.reply("No user specified");
}
}
}
});
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:89
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:1436
A container for a 64 bit unsigned value representing many things on discord. This value is known in d...
Definition snowflake.h:54
Represents a user on discord. May or may not be a member of a dpp::guild.
Definition user.h:163
static std::string get_mention(const snowflake &id)
Create a mentionable user.
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
auto run_once()
Run some code within an if() statement only once.
Definition once.h:41
@ co_sub_command
A sub-command.
Definition appcommand.h:59
@ co_user
A user snowflake id.
Definition appcommand.h:84
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition cluster.h:72
Details of a command within an interaction. This subobject represents the application command associa...
Definition appcommand.h:861
std::vector< command_data_option > options
Optional: the params + values from the user.
Definition appcommand.h:875
Each command option is a command line parameter. It can have a type (see dpp::command_option_type),...
Definition appcommand.h:208
interaction command
command interaction
Definition dispatcher.h:789
Session ready.
Definition dispatcher.h:1072
User has issued a slash command.
Definition dispatcher.h:806