Skip to content

Commit

Permalink
docs: added a page for default select menu values. Added a section in…
Browse files Browse the repository at this point in the history
… components3 for role select menus (#947)

Co-authored-by: Craig Edwards (Brain) <braindigitalis@users.noreply.github.com>
  • Loading branch information
Jaskowicz1 and braindigitalis authored Oct 16, 2023
1 parent b37e9ac commit 3def1a8
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 4 deletions.
46 changes: 46 additions & 0 deletions docpages/example_code/components3_rolemenu.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#include <dpp/dpp.h>

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<struct register_bot_commands>()) {
/* 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;
}
47 changes: 47 additions & 0 deletions docpages/example_code/default_select_value.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include <dpp/dpp.h>
#include <dpp/unicode_emoji.h>

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<struct register_bot_commands>()) {
/* 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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Binary file added docpages/images/default_select_value.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docpages/images/default_select_value_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 3def1a8

Please sign in to comment.