Discord now supports sending auto completion lists for slash command choices. To use this feature you can use code such as the example below:
#include <dpp/dpp.h>
int main()
{
if (dpp::run_once<struct register_bot_commands>()) {
bot.global_command_create(
dpp::slashcommand(
"blep",
"Send a random adorable animal photo", bot.me.id)
)
);
}
});
std::string animal = std::get<std::string>(event.get_parameter("animal"));
event.reply("Blep! You chose " + animal);
}
});
if (opt.focused) {
std::string uservalue = std::get<std::string>(opt.value);
bot.interaction_response_create(event.command.id, event.command.token, dpp::interaction_response(dpp::ir_autocomplete_reply)
.add_autocomplete_choice(dpp::command_option_choice("squids", "lots of squids"))
.add_autocomplete_choice(dpp::command_option_choice("cats", "a few cats"))
.add_autocomplete_choice(dpp::command_option_choice("dogs", "bucket of dogs"))
.add_autocomplete_choice(dpp::command_option_choice("elephants", "bottle of elephants"))
);
bot.log(dpp::ll_debug, "Autocomplete " + opt.name + " with value '" + uservalue + "' in field " + event.name);
break;
}
}
});
return 0;
}
The cluster class represents a group of shards and a command queue for sending and receiving commands...
Definition: cluster.h:84
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:982
slashcommand & add_option(const command_option &o)
Add an option (parameter)
std::function< void(const dpp::log_t &)> DPP_EXPORT cout_logger()
Get a default logger that outputs to std::cout. e.g.
@ co_string
Definition: appcommand.h:55
@ st_wait
Wait forever on a condition variable. The cluster will spawn threads for each shard and start() will ...
Definition: cluster.h:67
Discord requests that we fill a list of auto completion choices for a command option.
Definition: dispatcher.h:556
std::vector< dpp::command_option > options
auto completion options
Definition: dispatcher.h:580
Each command option is a command line parameter. It can have a type (see dpp::command_option_type),...
Definition: appcommand.h:154
command_option & set_auto_complete(bool autocomp)
Set the auto complete state.
interaction command
command interaction
Definition: dispatcher.h:490
Session ready.
Definition: dispatcher.h:766
User has issued a slash command.
Definition: dispatcher.h:501