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()
{
.set_description("Send a random adorable animal photo")
.set_application_id(bot.me.id)
)
);
});
dpp::command_interaction cmd_data = std::get<dpp::command_interaction>(event.command.data);
if (cmd_data.name == "blep") {
std::string animal = std::get<std::string>(event.get_parameter("animal"));
event.reply(dpp::ir_channel_message_with_source, "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;
}
}
});
});
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:236
uint8_t type
the type of interaction
Definition: slashcommand.h:446
Represents an application command, created by your bot either globally, or on a guild.
Definition: slashcommand.h:556
slashcommand & add_option(const command_option &o)
Add an option (parameter)
std::string DPP_EXPORT loglevel(dpp::loglevel in)
Convert a dpp::loglevel enum value to a string.
@ it_application_command
application command (slash command)
Definition: slashcommand.h:355
@ co_string
Definition: slashcommand.h:48
Discord requests that we fill a list of auto completion choices for a command option.
Definition: dispatcher.h:289
std::vector< dpp::command_option > options
auto completion options
Definition: dispatcher.h:318
Each command option is a command line parameter. It can have a type (see dpp::command_option_type),...
Definition: slashcommand.h:122
command_option & set_auto_complete(bool autocomp)
Set the auto complete state.
Create interaction.
Definition: dispatcher.h:173
interaction command
command interaction
Definition: dispatcher.h:255
Log messages.
Definition: dispatcher.h:104
loglevel severity
Definition: dispatcher.h:112
Session ready.
Definition: dispatcher.h:432