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

Function main

docpages/example_code/components.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() == "button") {
13 /* Create a message */
14 dpp::message msg(event.command.channel_id, "this text has a button");
15
16 /* Add an action row, and then a button within the action row. */
17 msg.add_component(
18 dpp::component().add_component(
19 dpp::component()
20 .set_label("Click me!")
21 .set_type(dpp::cot_button)
22 .set_emoji(dpp::unicode_emoji::smile)
23 .set_style(dpp::cos_danger)
24 .set_id("myid")
25 )
26 );
27
28 /* Reply to the user with our message. */
29 event.reply(msg);
30 }
31 });
32
33 /* When a user clicks your button, the on_button_click event will fire,
34 * containing the custom_id you defined in your button.
35 */
36 bot.on_button_click([&bot](const dpp::button_click_t& event) {
37 /* Button 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);
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("button", "Send a message with a button!", 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