| D++ (DPP) C++ Discord API Bot Library

Search
Loading...
Searching...
No Matches
dpp::command_option Struct Reference

Each command option is a command line parameter. It can have a type (see dpp::command_option_type), a name, a description, can be required or optional, and can have zero or more choices (for multiple choice), plus options. Adding options acts like sub-commands and can contain more options. More...

`#include <appcommand.h>`

Inheritance diagram for dpp::command_option:
[legend]
Collaboration diagram for dpp::command_option:
[legend]

## Public Member Functions

| command_option ()=default
| Construct a new command option object.
| command_option (command_option_type t, const std::string &name, const std::string &description, bool required=false)
| Construct a new command option object.
virtual | ~command_option ()=default
| Destroy the command option object.
command_option & | add_channel_type (const channel_type ch)
| Add channel type for option (only for co_channel type options).
command_option & | add_choice (const command_option_choice &o)
| Add a multiple choice option.
command_option & | add_file_type (std::string_view file_type)
| Add a file type (dpp::co_attachment) to filter for.
command_option & | add_localization (const std::string &language, const std::string &_name, const std::string &_description="")
| Add a localisation for this slash command option.
command_option & | add_option (const command_option &o)
| Add a sub-command option.
std::string | build_json (bool with_id=false) const
| Convert object to json string.
command_option & | fill_from_json (nlohmann::json *j)
| Convert object from nlohmann::json.
command_option & | set_auto_complete (bool autocomp)
| Set the auto complete state.
command_option & | set_max_length (command_option_range max_v)
| Set the maximum string length of the option. Must be between 1 and 6000 (inclusive). Only valid if the type is dpp::co_string.
command_option & | set_max_value (command_option_range max_v)
| Set the maximum numeric value of the option. Only valid if the type is dpp::co_number or dpp::co_integer.
command_option & | set_min_length (command_option_range min_v)
| Set the minimum string length of the option. Must be between 0 and 6000 (inclusive). Only valid if the type is dpp::co_string.
command_option & | set_min_value (command_option_range min_v)
| Set the minimum numeric value of the option. Only valid if the type is dpp::co_number or dpp::co_integer.
auto | to_json (bool with_id=false) const
| Convert object to nlohmann::json.

## Public Attributes

bool | autocomplete
| Does this option supports auto completion?
std::vector< channel_type > | channel_types
| Allowed channel types for channel snowflake id options.
std::vector< command_option_choice > | choices
| List of choices for multiple choice command.
std::string | description
| Option description (1-100 chars).
std::map< std::string, std::string > | description_localizations
| Localisations of command description.
std::vector< std::string > | file_types
| File types (dpp::co_attachment) to filter for; can be "image", "video", "audio", or any dot-prefixed extension such as ".pdf" (0-10).
bool | focused
| Is the user is typing in this field?
command_option_range | max_value
| Maximum value/length that can be entered, for dpp::co_number, dpp::co_integer and dpp::co_string types only.
command_option_range | min_value
| Minimum value/length that can be entered, for dpp::co_number, dpp::co_integer and dpp::co_string types only.
std::string | name
| Option name (1-32 chars).
std::map< std::string, std::string > | name_localizations
| Localisations of command name.
std::vector< command_option > | options
| An array of sub-commands (options).
bool | required
| Is this a mandatory parameter?
command_option_type | type
| Option type (what type of value is accepted).
command_value | value
| Set only by autocomplete when sent as part of an interaction.

## Protected Member Functions

command_option & | fill_from_json_impl (nlohmann::json *j)
| Fill object properties from JSON. Fills options recursively.

## Friends

struct | json_interface< command_option >

## Detailed Description

Each command option is a command line parameter. It can have a type (see dpp::command_option_type), a name, a description, can be required or optional, and can have zero or more choices (for multiple choice), plus options. Adding options acts like sub-commands and can contain more options.

## Constructor & Destructor Documentation

## ◆ command_option() [1/2]

dpp::command_option::command_option | ( |  | ) |

default

Construct a new command option object.

## ◆ ~command_option()

virtual dpp::command_option::~command_option | ( |  | ) |

virtual default

Destroy the command option object.

## ◆ command_option() [2/2]

dpp::command_option::command_option | ( | command_option_type | t,
|  | const std::string & | name,
|  | const std::string & | description,
|  | bool | required = false )

Construct a new command option object.

Parameters

  t | Option type
  name | Option name
  description | Option description
  required | True if this is a mandatory parameter

## Member Function Documentation

## ◆ add_channel_type()

command_option & dpp::command_option::add_channel_type | ( | const channel_type | ch | ) |

Add channel type for option (only for co_channel type options).

Parameters

  ch | type to set

Returns
  command_option& return a reference to self for chaining of calls

## ◆ add_choice()

command_option & dpp::command_option::add_choice | ( | const command_option_choice & | o | ) |

Add a multiple choice option.

Parameters

  o | choice to add

Returns
  command_option& returns a reference to self for chaining of calls

Exceptions

  dpp::logic_exception | command_option is an autocomplete, so choices cannot be added

## ◆ add_file_type()

command_option & dpp::command_option::add_file_type | ( | std::string_view | file_type | ) |

Add a file type (dpp::co_attachment) to filter for.

Parameters

  file_type | The type to filter for ("image"/"video"/"audio" or the file extension (begins with ".")).

Returns
  command_option& Reference to self

## ◆ add_localization()

command_option & dpp::command_option::add_localization | ( | const std::string & | language,
|  | const std::string & | _name,
|  | const std::string & | _description = "" )

Add a localisation for this slash command option.

See also
  https://discord.com/developers/docs/reference#locales

Parameters

  language | Name of language, see the list of locales linked to above
  _name | name of slash command option in the specified language
  _description | description of slash command option in the specified language (optional)

Returns
  command_option& reference to self for fluent chaining

## ◆ add_option()

command_option & dpp::command_option::add_option | ( | const command_option & | o | ) |

Add a sub-command option.

Parameters

  o | Sub-command option to add

Returns
  command_option& return a reference to self for chaining of calls

## ◆ build_json()

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

inline inherited

Convert object to json string.

Parameters

  with_id | Whether to include the ID or not

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

Returns
  std::string Json built from the structure

## ◆ fill_from_json()

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

inline inherited

Convert object from nlohmann::json.

Parameters

  j | nlohmann::json object

Returns
  T& Reference to self for fluent calling

## ◆ fill_from_json_impl()

command_option & dpp::command_option::fill_from_json_impl | ( | nlohmann::json * | j | ) |

protected

Fill object properties from JSON. Fills options recursively.

Parameters

  j | JSON to fill from

Returns
  command_option& Reference to self

## ◆ set_auto_complete()

command_option & dpp::command_option::set_auto_complete | ( | bool | autocomp | ) |

Set the auto complete state.

Parameters

  autocomp | True to enable auto completion for this option

Returns
  command_option& return a reference to self for chaining of calls

Exceptions

  dpp::logic_exception | You attempted to enable auto complete on a command_option that has choices added to it

## ◆ set_max_length()

command_option & dpp::command_option::set_max_length | ( | command_option_range | max_v | ) |

Set the maximum string length of the option. Must be between 1 and 6000 (inclusive). Only valid if the type is dpp::co_string.

Parameters

  max_v | Maximum value

Returns
  command_option& returns a reference to self for chaining of calls

## ◆ set_max_value()

command_option & dpp::command_option::set_max_value | ( | command_option_range | max_v | ) |

Set the maximum numeric value of the option. Only valid if the type is dpp::co_number or dpp::co_integer.

Parameters

  max_v | Maximum value

Returns
  command_option& returns a reference to self for chaining of calls

## ◆ set_min_length()

command_option & dpp::command_option::set_min_length | ( | command_option_range | min_v | ) |

Set the minimum string length of the option. Must be between 0 and 6000 (inclusive). Only valid if the type is dpp::co_string.

Parameters

  min_v | Minimum value

Returns
  command_option& returns a reference to self for chaining of calls

## ◆ set_min_value()

command_option & dpp::command_option::set_min_value | ( | command_option_range | min_v | ) |

Set the minimum numeric value of the option. Only valid if the type is dpp::co_number or dpp::co_integer.

Parameters

  min_v | Minimum value

Returns
  command_option& returns a reference to self for chaining of calls

## ◆ to_json()

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

inline inherited

Convert object to nlohmann::json.

Parameters

  with_id | Whether to include the ID or not

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

Returns
  json Json built from the structure

## Friends And Related Symbol Documentation

## ◆ json_interface< command_option >

friend struct json_interface< command_option >

friend

## Member Data Documentation

## ◆ autocomplete

bool dpp::command_option::autocomplete

Does this option supports auto completion?

## ◆ channel_types

std::vector<channel_type> dpp::command_option::channel_types

Allowed channel types for channel snowflake id options.

## ◆ choices

std::vector<command_option_choice> dpp::command_option::choices

List of choices for multiple choice command.

## ◆ description

std::string dpp::command_option::description

Option description (1-100 chars).

## ◆ description_localizations

std::map<std::string, std::string> dpp::command_option::description_localizations

Localisations of command description.

## ◆ file_types

std::vector<std::string> dpp::command_option::file_types

File types (dpp::co_attachment) to filter for; can be "image", "video", "audio", or any dot-prefixed extension such as ".pdf" (0-10).

## ◆ focused

bool dpp::command_option::focused

Is the user is typing in this field?

Note
  This is sent via autocomplete.

## ◆ max_value

command_option_range dpp::command_option::max_value

Maximum value/length that can be entered, for dpp::co_number, dpp::co_integer and dpp::co_string types only.

## ◆ min_value

command_option_range dpp::command_option::min_value

Minimum value/length that can be entered, for dpp::co_number, dpp::co_integer and dpp::co_string types only.

## ◆ name

std::string dpp::command_option::name

Option name (1-32 chars).

## ◆ name_localizations

std::map<std::string, std::string> dpp::command_option::name_localizations

Localisations of command name.

## ◆ options

std::vector<command_option> dpp::command_option::options

An array of sub-commands (options).

## ◆ required

bool dpp::command_option::required

Is this a mandatory parameter?

## ◆ type

command_option_type dpp::command_option::type

Option type (what type of value is accepted).

## ◆ value

command_value dpp::command_option::value

Set only by autocomplete when sent as part of an interaction.

D++ Library version 9.0.13 D++ Library version 9.0.12 D++ Library version 9.0.11 D++ Library version 9.0.10 D++ Library version 9.0.9 D++ Library version 9.0.8 D++ Library version 9.0.7 D++ Library version 9.0.6 D++ Library version 9.0.5 D++ Library version 9.0.4 D++ Library version 9.0.3 D++ Library version 9.0.2 D++ Library version 9.0.1 D++ Library version 9.0.0 D++ Library version 1.0.2 D++ Library version 1.0.1 D++ Library version 1.0.0