Discord now supports sending auto completion lists for slash command choices. To use this feature you can use code such as the example below:
{
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", std::string("lots of squids")))
.add_autocomplete_choice(dpp::command_option_choice("cats", std::string("a few cats")))
.add_autocomplete_choice(dpp::command_option_choice("dogs", std::string("bucket of dogs")))
.add_autocomplete_choice(dpp::command_option_choice("elephants", std::string("bottle of elephants")))
);
bot.log(dpp::ll_debug, "Autocomplete " + opt.name + " with value '" + uservalue + "' in field " + event.name);
break;
}
}
});
return 0;
}