dpp::component
dpp::json_interface< component >
message.h
struct friend struct json_interface< component > json_interface< component > dpp::component::json_interface< component > json_interface< component >
std::optional< uint32_t > std::optional<uint32_t> dpp::component::accent accent dpp::component::accent

Accent colour for container types (v2).

std::shared_ptr< component > std::shared_ptr<component> dpp::component::accessory accessory dpp::component::accessory

accessory component for components which support it (v2) Can be a button or a thumbnail.

std::vector< uint8_t > std::vector<uint8_t> dpp::component::channel_types channel_types 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 > std::vector<component> dpp::component::components components dpp::component::components

Sub components, buttons on an action row.

std::string std::string dpp::component::content content dpp::component::content

Text content for section and text display types (v2).

std::string std::string dpp::component::custom_id custom_id dpp::component::custom_id

Component id (for buttons, menus, text inputs). Maximum of 100 characters.

std::vector< component_default_value > std::vector<component_default_value> dpp::component::default_values default_values dpp::component::default_values

List of default values for auto-populated select menu components.

The amount of default values must be in the range defined by dpp::component::min_values and dpp::component::max_values.

Only available for auto-populated select menu components, which include dpp::cot_user_selectmenu, dpp::cot_role_selectmenu,

- dpp::cot_mentionable_selectmenu, and dpp::cot_channel_selectmenu components.

std::string std::string dpp::component::description description dpp::component::description

Description for media items (v2).

bool bool dpp::component::disabled disabled dpp::component::disabled

Disabled flag (for buttons).

partial_emoji partial_emoji dpp::component::emoji emoji dpp::component::emoji

The emoji for this component.

std::optional< embed_image > std::optional<embed_image> dpp::component::file file dpp::component::file

Unfurled file URL for file objects (v2) Should be in the format "attachment://...".

bool bool dpp::component::is_divider is_divider dpp::component::is_divider

can be set for separator types (v2)

std::string std::string dpp::component::label label dpp::component::label

Component label (for buttons, text inputs). Maximum of 80 characters.

int32_t int32_t dpp::component::max_length max_length dpp::component::max_length

Maximum length for text input (1-4000).

int32_t int32_t dpp::component::max_values max_values dpp::component::max_values

Maximum number of items that can be chosen for a select menu (0-25).

Use -1 to not set this. This is done by default.

std::vector< std::shared_ptr< component > > std::vector<std::shared_ptr<component> > dpp::component::media_gallery_items media_gallery_items dpp::component::media_gallery_items

Media gallery items for media galleries (v2).

int32_t int32_t dpp::component::min_length min_length dpp::component::min_length

Minimum length for text input (0-4000).

int32_t int32_t dpp::component::min_values min_values dpp::component::min_values

Minimum number of items that must be chosen for a select menu (0-25).

Use -1 to not set this. This is done by default.

std::vector< select_option > std::vector<select_option> dpp::component::options options dpp::component::options

Select options for select menus.

Only required and available for select menus of type dpp::cot_selectmenu

std::string std::string dpp::component::placeholder placeholder dpp::component::placeholder

Placeholder text for select menus and text inputs (max 150 characters).

bool bool dpp::component::required required dpp::component::required

Whether the text input is required to be filled.

dpp::snowflake dpp::snowflake dpp::component::sku_id sku_id dpp::component::sku_id

The SKU ID for premium upsell buttons.

separator_spacing separator_spacing dpp::component::spacing spacing dpp::component::spacing

Valid for separator types (v2).

bool bool dpp::component::spoiler spoiler dpp::component::spoiler

Spoiler state for media and file items.

component_style component_style dpp::component::style style dpp::component::style

Component style (for buttons).

text_style_type text_style_type dpp::component::text_style text_style dpp::component::text_style

Text style (for text inputs).

std::optional< embed_image > std::optional<embed_image> dpp::component::thumbnail thumbnail dpp::component::thumbnail

Unfurled media for thumbnail objects (v2).

component_type component_type dpp::component::type type dpp::component::type

Component type, either a button or action row.

std::string std::string dpp::component::url url dpp::component::url

URL for link types (dpp::cos_link). Maximum of 512 characters.

std::variant< std::monostate, std::string, int64_t, double > std::variant<std::monostate, std::string, int64_t, double> dpp::component::value value dpp::component::value

Value of the modal. Filled or valid when populated from an on_form_submit event, or from the set_value function.

component & component & dpp::component::fill_from_json_impl (nlohmann::json *j) fill_from_json_impl dpp::component::fill_from_json_impl nlohmann::json * j

Read class values from json object j

A json object to read from

A reference to self

dpp::component::component
()
component
dpp::component::component

Constructor.

virtual dpp::component::~component
()=default
~component
dpp::component::~component

Destructor.

component & component & dpp::component::add_channel_type (uint8_t ct) add_channel_type 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

component& reference to self

component & component & dpp::component::add_component (const component &c) add_component dpp::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.

Automatic creation of action rows is retained for backwards compatibility with components v1. If you want to add components v2, and do not want automatic creation of action rows, use dpp::component::add_component_v2() instead.

c

The sub-component to add

component& reference to self

component & component & dpp::component::add_component_v2 (const component &c) add_component_v2 dpp::component::add_component_v2 const component & c

Add a sub-component, does not automatically create action rows. This should be used for components v2 where you do not want to add action rows automatically.

c

The sub-component to add

component& reference to self

component & component & dpp::component::add_default_value (const snowflake id, const component_default_value_type type) add_default_value 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 & component & dpp::component::add_media_gallery_item (const component &media_gallery_item) add_media_gallery_item dpp::component::add_media_gallery_item const component & media_gallery_item

Add a media gallery item to a media gallery type (v2).

media_gallery_item

item to add

component & component & dpp::component::add_select_option (const select_option &option) add_select_option dpp::component::add_select_option const select_option & option

Add a select option.

option

option to add

component& Reference to self

std::string std::string dpp::json_interface< component >::build_json (bool with_id=false) const build_json dpp::json_interface< component >::build_json bool with_id false

Convert object to json string.

with_id

Whether to include the ID or not

Some fields are conditionally filled, do not rely on all fields being present

std::string Json built from the structure

component & component & dpp::json_interface< component >::fill_from_json (nlohmann::json *j) fill_from_json dpp::json_interface< component >::fill_from_json nlohmann::json * j

Convert object from nlohmann::json.

j

nlohmann::json object

T& Reference to self for fluent calling

component & component & dpp::component::set_accent (uint32_t accent_colour) set_accent dpp::component::set_accent uint32_t accent_colour

Set accent colour for container type (v2).

accent_colour

Accent colour for container

self

component & component & dpp::component::set_accessory (const component &accessory_component) set_accessory dpp::component::set_accessory const component & accessory_component

Set accessory component for components which support it. Can be a button or a thumbnail image.

accessory_component

accessory component

component & component & dpp::component::set_content (const std::string &text) set_content dpp::component::set_content const std::string & text

For text content types, set content.

Ignored for other types

text

text to set

component & component & dpp::component::set_default_value (std::string_view val) set_default_value 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& Reference to self

component & component & dpp::component::set_description (const std::string &text) set_description dpp::component::set_description const std::string & text

For media types, set description.

Ignored for other types

text

text to set

component & component & dpp::component::set_disabled (bool disable) set_disabled 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& Reference to self

component & component & dpp::component::set_divider (bool divider) set_divider dpp::component::set_divider bool divider

Set divider visibility for separator type (v2).

divider

true to show a visible divider

self

component & component & dpp::component::set_emoji (std::string_view name, dpp::snowflake id=0, bool animated=false) set_emoji dpp::component::set_emoji std::string_view 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& Reference to self

component & component & dpp::component::set_file (std::string_view attachment_url) set_file dpp::component::set_file std::string_view attachment_url

Set the attachment url for file type components. The format of the attachment url should be of the type "attachment://...".

attachment_url

url to attachment. Should have been attached via add_file().

self

component & component & dpp::component::set_id (std::string_view id) set_id 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.

The maximum length of the Custom ID is 100 UTF-8 codepoints. If your Custom ID is longer than this, it will be truncated.

component& Reference to self

component & component & dpp::component::set_label (std::string_view label) set_label 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& Reference to self

component & component & dpp::component::set_max_length (uint32_t max_l) set_max_length 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& Reference to self

component & component & dpp::component::set_max_values (uint32_t max_values) set_max_values 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& Reference to self

component & component & dpp::component::set_min_length (uint32_t min_l) set_min_length 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& Reference to self

component & component & dpp::component::set_min_values (uint32_t min_values) set_min_values 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& Reference to self

component & component & dpp::component::set_placeholder (std::string_view placeholder) set_placeholder 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& Reference to self

component & component & dpp::component::set_required (bool require) set_required 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& Reference to self

component & component & dpp::component::set_sku_id (dpp::snowflake sku) set_sku_id 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& reference to self

component & component & dpp::component::set_spacing (separator_spacing sep_spacing) set_spacing dpp::component::set_spacing separator_spacing sep_spacing

Set separator spacing for separator type (v2).

sep_spacing

separator spacing, small or large

self

component & component & dpp::component::set_spoiler (bool spoiler_enable) set_spoiler dpp::component::set_spoiler bool spoiler_enable

For media and file component types, set spoiler status.

Ignored for other types

spoiler_enable

True to enable spoiler masking

component & component & dpp::component::set_style (component_style cs) set_style 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& reference to self

component & component & dpp::component::set_text_style (text_style_type ts) set_text_style dpp::component::set_text_style text_style_type ts

Set the text style of a text component.

Sets type to `cot_text`

ts

Text style type to set

component& reference to self

component & component & dpp::component::set_thumbnail (std::string_view url) set_thumbnail dpp::component::set_thumbnail std::string_view url

Set component thumbnail for thumbnail type (v2.

url

The embed thumbnail url (only supports http(s) and attachments)

A reference to self so this method may be "chained".

component & component & dpp::component::set_type (component_type ct) set_type 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& reference to self

component & component & dpp::component::set_url (std::string_view url) set_url 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.

component& reference to self.

auto auto dpp::json_interface< component >::to_json (bool with_id=false) const to_json dpp::json_interface< component >::to_json bool with_id false

Convert object to nlohmann::json.

with_id

Whether to include the ID or not

Some fields are conditionally filled, do not rely on all fields being present

json Json built from the structure

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
dpp::json_interface< T >
dpp::json_interface< component >
< component >
T
bool
component_default_value_type
component_style
component_type
dpp::component
type
components
content
custom_id
description
label
placeholder
url
style
text_style
sku_id
max_length
max_values
min_length
min_values
options
channel_types
default_values
disabled
is_divider
required
spoiler
value
emoji
accessory
spacing
file
thumbnail
media_gallery_items
accent
dpp::component_default_value
type
id
dpp::json_interface< T >
dpp::json_interface< component >
< component >
dpp::json_interface< select_option >
< select_option >
dpp::partial_emoji
name
id
animated
dpp::select_option
description
label
value
is_default
emoji
dpp::snowflake
value
int32_t
separator_spacing
std::basic_string< Char >
optional< dpp::embed_image >
optional< uint32_t >
std::shared_ptr< T >
ptr
std::shared_ptr< dpp::component >
ptr
< dpp::component >
std::string
variant< std::monostate, std::string, int64_t, double >
std::vector< T >
elements
std::vector< dpp::component >
elements
< dpp::component >
std::vector< dpp::component_default_value >
elements
< dpp::component_default_value >
std::vector< dpp::select_option >
elements
< dpp::select_option >
std::vector< std::shared_ptr< dpp::component > >
elements
< std::shared_ptr< dpp::component > >
std::vector< uint8_t >
elements
< uint8_t >
text_style_type
uint64_t
uint8_t
- dpp::component
  accent
- dpp::component
  accessory
- dpp::component
  add_channel_type
- dpp::component
  add_component
- dpp::component
  add_component_v2
- dpp::component
  add_default_value
- dpp::component
  add_media_gallery_item
- dpp::component
  add_select_option
- dpp::component
  build_json
- dpp::component
  channel_types
- dpp::component
  component
- dpp::component
  components
- dpp::component
  content
- dpp::component
  custom_id
- dpp::component
  default_values
- dpp::component
  description
- dpp::component
  disabled
- dpp::component
  emoji
- dpp::component
  file
- dpp::component
  fill_from_json
- dpp::component
  fill_from_json_impl
- dpp::component
  is_divider
- dpp::component
  json_interface< component >
- dpp::component
  label
- dpp::component
  max_length
- dpp::component
  max_values
- dpp::component
  media_gallery_items
- dpp::component
  min_length
- dpp::component
  min_values
- dpp::component
  options
- dpp::component
  placeholder
- dpp::component
  required
- dpp::component
  set_accent
- dpp::component
  set_accessory
- dpp::component
  set_content
- dpp::component
  set_default_value
- dpp::component
  set_description
- dpp::component
  set_disabled
- dpp::component
  set_divider
- dpp::component
  set_emoji
- dpp::component
  set_file
- dpp::component
  set_id
- dpp::component
  set_label
- dpp::component
  set_max_length
- dpp::component
  set_max_values
- dpp::component
  set_min_length
- dpp::component
  set_min_values
- dpp::component
  set_placeholder
- dpp::component
  set_required
- dpp::component
  set_sku_id
- dpp::component
  set_spacing
- dpp::component
  set_spoiler
- dpp::component
  set_style
- dpp::component
  set_text_style
- dpp::component
  set_thumbnail
- dpp::component
  set_type
- dpp::component
  set_url
- dpp::component
  sku_id
- dpp::component
  spacing
- dpp::component
  spoiler
- dpp::component
  style
- dpp::component
  text_style
- dpp::component
  thumbnail
- dpp::component
  to_json
- dpp::component
  type
- dpp::component
  url
- dpp::component
  value
- dpp::component
  ~component