D++ (DPP)
C++ Discord API Bot Library
|
Represents the component object. A component is a clickable button or drop down list within a discord message, where the buttons emit on_button_click events when the user interacts with them. More...
Public Member Functions | |
component () | |
Constructor. More... | |
virtual | ~component ()=default |
Destructor. More... | |
component & | add_channel_type (uint8_t ct) |
Add a channel type to include in the channel select component (dpp::cot_channel_selectmenu) More... | |
component & | set_type (component_type ct) |
Set the type of the component. Button components (type dpp::cot_button) should always be contained within an action row (type dpp::cot_action_row). As described below, many of the other methods automatically set this to the correct type so usually you should not need to manually call component::set_type(). More... | |
component & | set_sku_id (dpp::snowflake sku) |
Set the SKU ID for a premium upsell button This is only valid for premium upsell buttons of type cos_premium. It indicates which premium package to link to when the button is clicked. More... | |
component & | set_text_style (text_style_type ts) |
Set the text style of a text component. More... | |
component & | set_label (std::string_view label) |
Set the label of the component, e.g. button text. For action rows, this field is ignored. Setting the label will auto-set the type to dpp::cot_button. More... | |
component & | set_default_value (std::string_view val) |
Set the default value of the text input component. For action rows, this field is ignored. Setting the value will auto-set the type to dpp::cot_text. More... | |
component & | set_url (std::string_view url) |
Set the url for dpp::cos_link types. Calling this function sets the style to dpp::cos_link and the type to dpp::cot_button. More... | |
component & | set_style (component_style cs) |
Set the style of the component, e.g. button colour. For action rows, this field is ignored. Setting the style will auto-set the type to dpp::cot_button. More... | |
component & | set_id (std::string_view id) |
Set the id of the component. For action rows, this field is ignored. Setting the id will auto-set the type to dpp::cot_button. More... | |
component & | set_disabled (bool disable) |
Set the component to disabled. Defaults to false on all created components. More... | |
component & | set_required (bool require) |
Set if this component is required. Defaults to false on all created components. More... | |
component & | set_placeholder (std::string_view placeholder) |
Set the placeholder. More... | |
component & | set_min_values (uint32_t min_values) |
Set the minimum number of items that must be chosen for a select menu. More... | |
component & | set_max_values (uint32_t max_values) |
Set the maximum number of items that can be chosen for a select menu. More... | |
component & | set_min_length (uint32_t min_l) |
Set the minimum input length for a text input. More... | |
component & | set_max_length (uint32_t max_l) |
Set the maximum input length for a text input. More... | |
component & | add_select_option (const select_option &option) |
Add a select option. More... | |
component & | add_component (const component &c) |
Add a sub-component, only valid for action rows. Adding subcomponents to a component will automatically set this component's type to dpp::cot_action_row. More... | |
component & | add_default_value (const snowflake id, const component_default_value_type type) |
Add a default value. More... | |
component & | set_emoji (std::string_view name, dpp::snowflake id=0, bool animated=false) |
Set the emoji of the current sub-component. More... | |
template<typename U = T, typename = decltype(std::declval<U&>().fill_from_json_impl(std::declval<nlohmann::json*>()))> | |
T & | fill_from_json (nlohmann::json *j) |
Convert object from nlohmann::json. More... | |
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))> | |
auto | to_json (bool with_id=false) const |
Convert object to nlohmann::json. More... | |
template<typename U = T, typename = decltype(std::declval<U&>().to_json_impl(bool{}))> | |
std::string | build_json (bool with_id=false) const |
Convert object to json string. More... | |
Public Attributes | |
component_type | type |
Component type, either a button or action row. More... | |
std::vector< component > | components |
Sub components, buttons on an action row. More... | |
std::string | label |
Component label (for buttons, text inputs). Maximum of 80 characters. More... | |
component_style | style |
Component style (for buttons). More... | |
text_style_type | text_style |
Text style (for text inputs). More... | |
std::string | custom_id |
Component id (for buttons, menus, text inputs). Maximum of 100 characters. More... | |
std::string | url |
URL for link types (dpp::cos_link). Maximum of 512 characters. More... | |
dpp::snowflake | sku_id |
The SKU ID for premium upsell buttons. More... | |
std::string | placeholder |
Placeholder text for select menus and text inputs (max 150 characters) More... | |
int32_t | min_values |
Minimum number of items that must be chosen for a select menu (0-25). More... | |
int32_t | max_values |
Maximum number of items that can be chosen for a select menu (0-25). More... | |
int32_t | min_length |
Minimum length for text input (0-4000) More... | |
int32_t | max_length |
Maximum length for text input (1-4000) More... | |
std::vector< select_option > | options |
Select options for select menus. More... | |
std::vector< uint8_t > | channel_types |
List of channel types (dpp::channel_type) to include in the channel select component (dpp::cot_channel_selectmenu) More... | |
std::vector< component_default_value > | default_values |
List of default values for auto-populated select menu components. More... | |
bool | disabled |
Disabled flag (for buttons) More... | |
bool | required |
Whether the text input is required to be filled. More... | |
std::variant< std::monostate, std::string, int64_t, double > | value |
Value of the modal. Filled or valid when populated from an on_form_submit event, or from the set_value function. More... | |
partial_emoji | emoji |
The emoji for this component. More... | |
Protected Member Functions | |
component & | fill_from_json_impl (nlohmann::json *j) |
Friends | |
struct | json_interface< component > |
Represents the component object. A component is a clickable button or drop down list within a discord message, where the buttons emit on_button_click events when the user interacts with them.
You should generally define one component object and then insert one or more additional components into it using component::add_component(), so that the parent object is an action row and the child objects are buttons.
dpp::component::component | ( | ) |
Constructor.
|
virtualdefault |
Destructor.
component& dpp::component::add_channel_type | ( | uint8_t | ct | ) |
Add a channel type to include in the channel select component (dpp::cot_channel_selectmenu)
ct | The dpp::channel_type |
Add a sub-component, only valid for action rows. Adding subcomponents to a component will automatically set this component's type to dpp::cot_action_row.
c | The sub-component to add |
component& dpp::component::add_default_value | ( | const snowflake | id, |
const component_default_value_type | type | ||
) |
Add a default value.
id | Default value. ID of a user, role, or channel |
type | The type this default value represents |
component& dpp::component::add_select_option | ( | const select_option & | option | ) |
Add a select option.
option | option to add |
|
inlineinherited |
Convert object to json string.
with_id | Whether to include the ID or not |
|
inlineinherited |
Convert object from nlohmann::json.
j | nlohmann::json object |
|
protected |
Read class values from json object
j | A json object to read from |
component& dpp::component::set_default_value | ( | std::string_view | val | ) |
Set the default value of the text input component. For action rows, this field is ignored. Setting the value will auto-set the type to dpp::cot_text.
val | Value text to set. It will be truncated to the maximum length of 4000 UTF-8 characters. |
component& dpp::component::set_disabled | ( | bool | disable | ) |
Set the component to disabled. Defaults to false on all created components.
disable | True to disable the component, False to enable the component. |
component& dpp::component::set_emoji | ( | std::string_view | name, |
dpp::snowflake | id = 0 , |
||
bool | animated = false |
||
) |
Set the emoji of the current sub-component.
name | Emoji name, or unicode character to use |
id | Emoji id, for custom emojis only. |
animated | True if the custom emoji is animated. |
component& dpp::component::set_id | ( | std::string_view | id | ) |
Set the id of the component. For action rows, this field is ignored. Setting the id will auto-set the type to dpp::cot_button.
id | Custom ID string to set. This ID will be sent for any on_button_click events related to the button. |
component& dpp::component::set_label | ( | std::string_view | label | ) |
Set the label of the component, e.g. button text. For action rows, this field is ignored. Setting the label will auto-set the type to dpp::cot_button.
label | Label text to set. It will be truncated to the maximum length of 80 UTF-8 characters. |
component& dpp::component::set_max_length | ( | uint32_t | max_l | ) |
Set the maximum input length for a text input.
max_l | max length to set (1-4000) |
component& dpp::component::set_max_values | ( | uint32_t | max_values | ) |
Set the maximum number of items that can be chosen for a select menu.
max_values | max value to set (0-25) |
component& dpp::component::set_min_length | ( | uint32_t | min_l | ) |
Set the minimum input length for a text input.
min_l | min length to set (0-4000) |
component& dpp::component::set_min_values | ( | uint32_t | min_values | ) |
Set the minimum number of items that must be chosen for a select menu.
min_values | min value to set (0-25) |
component& dpp::component::set_placeholder | ( | std::string_view | placeholder | ) |
Set the placeholder.
placeholder | placeholder string. It will be truncated to the maximum length of 150 UTF-8 characters for select menus, and 100 UTF-8 characters for modals. |
component& dpp::component::set_required | ( | bool | require | ) |
Set if this component is required. Defaults to false on all created components.
require | True to require this, false to make it optional. |
component& dpp::component::set_sku_id | ( | dpp::snowflake | sku | ) |
Set the SKU ID for a premium upsell button This is only valid for premium upsell buttons of type cos_premium. It indicates which premium package to link to when the button is clicked.
sku | The SKU ID |
component& dpp::component::set_style | ( | component_style | cs | ) |
Set the style of the component, e.g. button colour. For action rows, this field is ignored. Setting the style will auto-set the type to dpp::cot_button.
cs | Component style to set |
component& dpp::component::set_text_style | ( | text_style_type | ts | ) |
Set the text style of a text component.
cot_text
ts | Text style type to set |
component& dpp::component::set_type | ( | component_type | ct | ) |
Set the type of the component. Button components (type dpp::cot_button) should always be contained within an action row (type dpp::cot_action_row). As described below, many of the other methods automatically set this to the correct type so usually you should not need to manually call component::set_type().
ct | The component type |
component& dpp::component::set_url | ( | std::string_view | url | ) |
Set the url for dpp::cos_link types. Calling this function sets the style to dpp::cos_link and the type to dpp::cot_button.
url | URL to set. It will be truncated to the maximum length of 512 UTF-8 characters. |
|
inlineinherited |
Convert object to nlohmann::json.
with_id | Whether to include the ID or not |
|
friend |
std::vector<uint8_t> dpp::component::channel_types |
List of channel types (dpp::channel_type) to include in the channel select component (dpp::cot_channel_selectmenu)
std::vector<component> dpp::component::components |
Sub components, buttons on an action row.
std::string dpp::component::custom_id |
Component id (for buttons, menus, text inputs). Maximum of 100 characters.
std::vector<component_default_value> dpp::component::default_values |
List of default values for auto-populated select menu components.
bool dpp::component::disabled |
Disabled flag (for buttons)
partial_emoji dpp::component::emoji |
The emoji for this component.
std::string dpp::component::label |
Component label (for buttons, text inputs). Maximum of 80 characters.
int32_t dpp::component::max_length |
Maximum length for text input (1-4000)
int32_t dpp::component::max_values |
Maximum number of items that can be chosen for a select menu (0-25).
int32_t dpp::component::min_length |
Minimum length for text input (0-4000)
int32_t dpp::component::min_values |
Minimum number of items that must be chosen for a select menu (0-25).
std::vector<select_option> dpp::component::options |
Select options for select menus.
std::string dpp::component::placeholder |
Placeholder text for select menus and text inputs (max 150 characters)
bool dpp::component::required |
Whether the text input is required to be filled.
dpp::snowflake dpp::component::sku_id |
The SKU ID for premium upsell buttons.
component_style dpp::component::style |
Component style (for buttons).
text_style_type dpp::component::text_style |
Text style (for text inputs).
component_type dpp::component::type |
Component type, either a button or action row.
std::string dpp::component::url |
URL for link types (dpp::cos_link). Maximum of 512 characters.
std::variant<std::monostate, std::string, int64_t, double> dpp::component::value |
Value of the modal. Filled or valid when populated from an on_form_submit event, or from the set_value function.