Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: added a page for default select menu values. Added a section in components3 for role select menus #947

Merged
merged 4 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions docpages/example_code/components3_rolemenu.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.
*
* 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.
Loading