Debian Codegraph @

docpages/example_code/default_select_value.cpp

raw symbols SCIP
1 #include <dpp/dpp.h>
2 #include <dpp/unicode_emoji.h>
3
4 int main() {
5 dpp::cluster bot("token");
6
7 bot.on_log(dpp::utility::cout_logger());
8
9 /* The event is fired when someone issues your commands */
10 bot.on_slashcommand([](const dpp::slashcommand_t& event) {
11 /* Check which command they ran */
12 if (event.command.get_command_name() == "select") {
13 /* Create a message */
14 dpp::message msg(event.command.channel_id, "This text has a select menu!");
15
16 /* Add an action row, and a select menu within the action row.
17 *
18 * Your default values are limited to max_values,
19 * meaning you can't add more default values than the allowed max values.
20 */
21 msg.add_component(
22 dpp::component().add_component(
23 dpp::component()
24 .set_type(dpp::cot_role_selectmenu)
25 .set_min_values(2)
26 .set_max_values(2)
27 .add_default_value(dpp::snowflake{667756886443163648}, dpp::cdt_role)
28 .set_id("myselectid")
29 )
30 );
31
32 /* Reply to the user with our message. */
33 event.reply(msg);
34 }
35 });
36
37 bot.on_ready([&bot](const dpp::ready_t& event) {
38 if (dpp::run_once<struct register_bot_commands>()) {
39 /* Create and register a command when the bot is ready */
40 bot.global_command_create(dpp::slashcommand("select", "Select something at random!", bot.me.id));
41 }
42 });
43
44 bot.start(dpp::st_wait);
45
46 return 0;
47 }