MCPcopy Create free account
hub / github.com/brainboxdotcc/DPP / main

Function main

docpages/example_code/components3.cpp:4–53  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2#include <dpp/unicode_emoji.h>
3
4int 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([&bot](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 msg.add_component(
18 dpp::component().add_component(
19 dpp::component()
20 .set_type(dpp::cot_selectmenu)
21 .set_placeholder("Pick something")
22 .add_select_option(dpp::select_option("label1","value1","description1").set_emoji(dpp::unicode_emoji::smile))
23 .add_select_option(dpp::select_option("label2","value2","description2").set_emoji(dpp::unicode_emoji::slight_smile))
24 .set_id("myselectid")
25 )
26 );
27
28 /* Reply to the user with our message. */
29 event.reply(msg);
30 }
31 });
32
33 /* When a user clicks your select menu , the on_select_click event will fire,
34 * containing the custom_id you defined in your select menu.
35 */
36 bot.on_select_click([&bot](const dpp::select_click_t & event) {
37 /* Select clicks are still interactions, and must be replied to in some form to
38 * prevent the "this interaction has failed" message from Discord to the user.
39 */
40 event.reply("You clicked " + event.custom_id + " and chose: " + event.values[0]);
41 });
42
43 bot.on_ready([&bot](const dpp::ready_t& event) {
44 if (dpp::run_once<struct register_bot_commands>()) {
45 /* Create and register a command when the bot is ready */
46 bot.global_command_create(dpp::slashcommand("select", "Select something at random!", bot.me.id));
47 }
48 });
49
50 bot.start(dpp::st_wait);
51
52 return 0;
53}

Callers

nothing calls this directly

Calls 5

cout_loggerFunction · 0.85
get_command_nameMethod · 0.80
global_command_createMethod · 0.80
startMethod · 0.80
replyMethod · 0.45

Tested by

no test coverage detected