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() {
if (dpp::run_once<struct register_bot_commands>()) {
image.add_option(
);
image.add_option(
);
bot.global_command_create(image);
}
});
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");
}
}
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");
}
}
}
});
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:84
An interaction represents a user running a command and arrives via the dpp::cluster::on_interaction_c...
Definition: appcommand.h:662
std::string get_command_name() const
Get the command name for a command interaction.
const dpp::user & get_resolved_user(snowflake id) const
Get a user associated with the slash command from the resolved list. The resolved list contains assoc...
command_interaction get_command_interaction() const
Get the command interaction object.
Represents an application command, created by your bot either globally, or on a guild.
Definition: appcommand.h:982
A container for a 64 bit unsigned value representing many things on discord. This value is known in d...
Definition: snowflake.h:48
Represents a user on discord. May or may not be a member of a dpp::guild.
Definition: user.h:88
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.
@ co_sub_command
Definition: appcommand.h:51
@ co_user
Definition: appcommand.h:61
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:67
Details of a command within an interaction. This subobject represents the application command associa...
Definition: appcommand.h:575
std::vector< command_data_option > options
Optional: the params + values from the user.
Definition: appcommand.h:578
Each command option is a command line parameter. It can have a type (see dpp::command_option_type),...
Definition: appcommand.h:154
Session ready.
Definition: dispatcher.h:766
User has issued a slash command.
Definition: dispatcher.h:501