diff --git a/docpages/example_code/components3_rolemenu.cpp b/docpages/example_code/components3_rolemenu.cpp new file mode 100644 index 0000000000..ed4f2b9b25 --- /dev/null +++ b/docpages/example_code/components3_rolemenu.cpp @@ -0,0 +1,46 @@ +#include + +int main() { + dpp::cluster bot("token"); + + bot.on_log(dpp::utility::cout_logger()); + + /* The event is fired when someone issues your commands */ + bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) { + /* Check which command they ran */ + if (event.command.get_command_name() == "select") { + /* Create a message */ + dpp::message msg(event.command.channel_id, "This text has a select menu!"); + + /* Add an action row, and a select menu within the action row. + * + * By default, max values is 1, meaning people can only pick 1 option. + * We're changing this to two, so people can select multiple options! + * We'll also set the min_values to 2 so people have to pick another value! + */ + msg.add_component( + dpp::component().add_component( + dpp::component() + .set_type(dpp::cot_role_selectmenu) + .set_min_values(2) + .set_max_values(2) + .set_id("myselectid") + ) + ); + + /* Reply to the user with our message. */ + event.reply(msg); + } + }); + + bot.on_ready([&bot](const dpp::ready_t& event) { + if (dpp::run_once()) { + /* Create and register a command when the bot is ready */ + bot.global_command_create(dpp::slashcommand("select", "Select something at random!", bot.me.id)); + } + }); + + bot.start(dpp::st_wait); + + return 0; +} diff --git a/docpages/example_code/default_select_value.cpp b/docpages/example_code/default_select_value.cpp new file mode 100644 index 0000000000..ace6b0cf5b --- /dev/null +++ b/docpages/example_code/default_select_value.cpp @@ -0,0 +1,47 @@ +#include +#include + +int main() { + dpp::cluster bot("token"); + + bot.on_log(dpp::utility::cout_logger()); + + /* The event is fired when someone issues your commands */ + bot.on_slashcommand([&bot](const dpp::slashcommand_t& event) { + /* Check which command they ran */ + if (event.command.get_command_name() == "select") { + /* Create a message */ + dpp::message msg(event.command.channel_id, "This text has a select menu!"); + + /* Add an action row, and a select menu within the action row. + * + * Your default values are limited to max_values, + * meaning you can't add more default values than the allowed max values. + */ + msg.add_component( + dpp::component().add_component( + dpp::component() + .set_type(dpp::cot_role_selectmenu) + .set_min_values(2) + .set_max_values(2) + .add_default_value(dpp::snowflake{667756886443163648}, dpp::cdt_role) + .set_id("myselectid") + ) + ); + + /* Reply to the user with our message. */ + event.reply(msg); + } + }); + + bot.on_ready([&bot](const dpp::ready_t& event) { + if (dpp::run_once()) { + /* Create and register a command when the bot is ready */ + bot.global_command_create(dpp::slashcommand("select", "Select something at random!", bot.me.id)); + } + }); + + bot.start(dpp::st_wait); + + return 0; +} \ No newline at end of file diff --git a/docpages/example_programs/interactions_and_components/components-menu.md b/docpages/example_programs/interactions_and_components/components-menu.md index f7fed09ecc..2c58e530c8 100644 --- a/docpages/example_programs/interactions_and_components/components-menu.md +++ b/docpages/example_programs/interactions_and_components/components-menu.md @@ -2,6 +2,7 @@ Components are anything that can be attached to a message or a \ref modal-dialog-interactions "modal" and interacted with, for example buttons and select menus. Due to being \ref interactions-and-components "interactions", they benefit from a low rate limit and are much more efficient than the old ways of using reactions for this purpose. -* \subpage components "Button components" -* \subpage components2 "Advanced button components" -* \subpage components3 "Select menu components" +* \subpage components +* \subpage components2 +* \subpage components3 +* \subpage default_select_value diff --git a/docpages/example_programs/interactions_and_components/components/components3.md b/docpages/example_programs/interactions_and_components/components/components3.md index e3ac023c23..cc4412141e 100644 --- a/docpages/example_programs/interactions_and_components/components/components3.md +++ b/docpages/example_programs/interactions_and_components/components/components3.md @@ -1,5 +1,15 @@ \page components3 Using select menu components -This example demonstrates creating a select menu, receiving select menu clicks and sending a response message. +This tutorial will cover creating two types of select menus: +- A generic select menu with just text +- An auto-populated role select menu. + +This first example demonstrates creating a select menu, receiving select menu clicks, and sending a response message. \include{cpp} components3.cpp + +This second example demonstrates creating a role select menu that is auto-populated by discord, and allowing people to select two options! + +\note This type of select menu, along with other types (these types being: user, role, mentionable, and channel), always auto-fill. You never need to define the data in these types of select menus. All select menu types allow you to select multiple options. + +\include{cpp} components3_rolemenu.cpp diff --git a/docpages/example_programs/interactions_and_components/components/default_select_value.md b/docpages/example_programs/interactions_and_components/components/default_select_value.md new file mode 100644 index 0000000000..7c39979fcc --- /dev/null +++ b/docpages/example_programs/interactions_and_components/components/default_select_value.md @@ -0,0 +1,13 @@ +\page default_select_value Setting default values on select menus. + +This tutorial will cover how to set the default value for a select menu (that isn't a text select menu)! + +\note **This only works for the following types of select menus: user, role, mentionable, and channel.** The default type of a select menu (as shown in \ref components3 "this page") does not work for this, as that supports a "placeholder". + +\include{cpp} default_select_value.cpp + +If all went well, you should have something like this! + +\image html default_select_value.png + +\image html default_select_value_2.png diff --git a/docpages/images/default_select_value.png b/docpages/images/default_select_value.png new file mode 100644 index 0000000000..09dbef3e14 Binary files /dev/null and b/docpages/images/default_select_value.png differ diff --git a/docpages/images/default_select_value_2.png b/docpages/images/default_select_value_2.png new file mode 100644 index 0000000000..73f6f6a916 Binary files /dev/null and b/docpages/images/default_select_value_2.png differ