|
| 1 | +#include <dpp/dpp.h> |
| 2 | + |
| 3 | +int main() { |
| 4 | + dpp::cluster bot("token"); |
| 5 | + |
| 6 | + bot.on_log(dpp::utility::cout_logger()); |
| 7 | + |
| 8 | + bot.on_ready([&bot](const auto& event) { |
| 9 | + if (dpp::run_once<struct boot_t>()) { |
| 10 | + bot.global_bulk_command_create({ dpp::slashcommand("cats", "I love cats", bot.me.id) }); |
| 11 | + } |
| 12 | + }); |
| 13 | + |
| 14 | + bot.on_button_click([](const dpp::button_click_t& event) { |
| 15 | + event.reply("You declared your love for cats by clicking button id: " + event.custom_id); |
| 16 | + }); |
| 17 | + |
| 18 | + /* This is a detailed example of using many different types of component. For a complete |
| 19 | + * list of supported components, see the Discord developer documentation and the definition |
| 20 | + * of dpp::component_type. |
| 21 | + */ |
| 22 | + bot.register_command("cats", [](const dpp::slashcommand_t& e) { |
| 23 | + e.reply(dpp::message() |
| 24 | + /* Remember to set the message flag for components v2 */ |
| 25 | + .set_flags(dpp::m_using_components_v2).add_component_v2( |
| 26 | + /* Reply with a container... */ |
| 27 | + dpp::component() |
| 28 | + .set_type(dpp::cot_container) |
| 29 | + .set_accent(dpp::utility::rgb(255, 0, 0)) |
| 30 | + .set_spoiler(true) |
| 31 | + .add_component_v2( |
| 32 | + /* ...which contains a section... */ |
| 33 | + dpp::component() |
| 34 | + .set_type(dpp::cot_section) |
| 35 | + .add_component_v2( |
| 36 | + /* ...with text... */ |
| 37 | + dpp::component() |
| 38 | + .set_type(dpp::cot_text_display) |
| 39 | + .set_content("Click if you love cats") |
| 40 | + ) |
| 41 | + .set_accessory( |
| 42 | + /* ...and an accessory button to the right */ |
| 43 | + dpp::component() |
| 44 | + .set_type(dpp::cot_button) |
| 45 | + .set_label("Click me") |
| 46 | + .set_style(dpp::cos_danger) |
| 47 | + .set_id("button") |
| 48 | + ) |
| 49 | + ) |
| 50 | + ).add_component_v2( |
| 51 | + /* ... with a large visible divider between... */ |
| 52 | + dpp::component() |
| 53 | + .set_type(dpp::cot_separator) |
| 54 | + .set_spacing(dpp::sep_large) |
| 55 | + .set_divider(true) |
| 56 | + ).add_component_v2( |
| 57 | + /* ... followed by a media gallery... */ |
| 58 | + dpp::component() |
| 59 | + .set_type(dpp::cot_media_gallery) |
| 60 | + .add_media_gallery_item( |
| 61 | + /* ...containing one cat pic (obviously) */ |
| 62 | + dpp::component() |
| 63 | + .set_type(dpp::cot_thumbnail) |
| 64 | + .set_description("A cat") |
| 65 | + .set_thumbnail("https://www.catster.com/wp-content/uploads/2023/11/Beluga-Cat-e1714190563227.webp") |
| 66 | + ) |
| 67 | + )); |
| 68 | + }); |
| 69 | + |
| 70 | + bot.start(dpp::st_wait); |
| 71 | +} |
0 commit comments