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...
#include <message.h>
Classes | |
struct | inner_emoji |
Public Member Functions | |
component () | |
~component ()=default | |
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_label (const std::string &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_url (const std::string &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 (const std::string &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_placeholder (const std::string &placeholder) |
Set the placeholder. More... | |
component & | set_min_values (uint32_t min_values) |
Set the min value. More... | |
component & | set_max_values (uint32_t max_values) |
Set the max value. 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 & | set_emoji (const std::string &name, dpp::snowflake id=0, bool animated=false) |
Set the emoji of the current sub-component. Only valid for buttons. Adding an emoji to a component will automatically set this components type to dpp::cot_button. One or both of name and id must be set. For a built in unicode emoji, you only need set name, and should set it to a unicode character e.g. "😄". For custom emojis, set the name to the name of the emoji on the guild, and the id to the emoji's ID. Setting the animated boolean is only valid for custom emojis. More... | |
component & | fill_from_json (nlohmann::json *j) |
Public Attributes | |
component_type | type |
std::vector< component > | components |
std::string | label |
component_style | style |
std::string | custom_id |
std::string | url |
std::string | placeholder |
int32_t | min_values |
int32_t | max_values |
std::vector< select_option > | options |
bool | disabled |
struct dpp::component::inner_emoji | emoji |
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
|
default |
Destructor
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_select_option | ( | const select_option & | option | ) |
Add a select option.
option | option to add |
component & dpp::component::fill_from_json | ( | nlohmann::json * | j | ) |
Read class values from json object
j | A json object to read from |
component & dpp::component::set_disabled | ( | bool | disable | ) |
Set the component to disabled. Defaults to false on all created components.
disable | True to disable, false to disable. |
component & dpp::component::set_emoji | ( | const std::string & | name, |
dpp::snowflake | id = 0 , |
||
bool | animated = false |
||
) |
Set the emoji of the current sub-component. Only valid for buttons. Adding an emoji to a component will automatically set this components type to dpp::cot_button. One or both of name and id must be set. For a built in unicode emoji, you only need set name, and should set it to a unicode character e.g. "😄". For custom emojis, set the name to the name of the emoji on the guild, and the id to the emoji's ID. Setting the animated boolean is only valid for custom emojis.
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 | ( | const std::string & | 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 | ( | const std::string & | 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 |
component & dpp::component::set_max_values | ( | uint32_t | max_values | ) |
Set the max value.
max_values | max value to set |
component & dpp::component::set_min_values | ( | uint32_t | min_values | ) |
Set the min value.
min_values | min value to set |
component & dpp::component::set_placeholder | ( | const std::string & | placeholder | ) |
Set the placeholder.
placeholder | placeholder string |
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_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 | ( | const std::string & | 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, maximum length of 512 characters |
std::vector<component> dpp::component::components |
Sub commponents, buttons on an action row
std::string dpp::component::custom_id |
Component id (for buttons). Maximum of 100 characters.
bool dpp::component::disabled |
Disabled flag (for buttons)
struct dpp::component::inner_emoji dpp::component::emoji |
std::string dpp::component::label |
Component label (for buttons). Maximum of 80 characters.
int32_t dpp::component::max_values |
Maximum number of selectable values for a select menu. -1 to not set this.
int32_t dpp::component::min_values |
Minimum number of selectable values for a select menu. -1 to not set this
std::vector<select_option> dpp::component::options |
Select options for select menus
std::string dpp::component::placeholder |
Placeholder text for select menus
component_style dpp::component::style |
Component style (for buttons)
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.