Each command option is a command line parameter. More...
#include "appcommand.h"
Public Member Functions | |
command_option ()=default | |
Construct a new command option object. More... | |
command_option (command_option_type t, const std::string &name, const std::string &description, bool required=false) | |
Construct a new command option object. More... | |
virtual | ~command_option ()=default |
Destroy the command option object. More... | |
command_option & | add_channel_type (const channel_type ch) |
Add channel type for option (only for co_channel type options) More... | |
command_option & | add_choice (const command_option_choice &o) |
Add a multiple choice option. More... | |
command_option & | add_localization (const std::string &language, const std::string &_name, const std::string &_description="") |
Add a localisation for this slash command option. More... | |
command_option & | add_option (const command_option &o) |
Add a sub-command option. More... | |
std::string | build_json (bool with_id=false) const |
Convert object to json string. More... | |
command_option & | fill_from_json (nlohmann::json *j) |
Convert object from nlohmann::json. More... | |
command_option & | set_auto_complete (bool autocomp) |
Set the auto complete state. More... | |
command_option & | set_max_length (command_option_range max_v) |
Set the maximum string length of the option. More... | |
command_option & | set_max_value (command_option_range max_v) |
Set the maximum numeric value of the option. More... | |
command_option & | set_min_length (command_option_range min_v) |
Set the minimum string length of the option. More... | |
command_option & | set_min_value (command_option_range min_v) |
Set the minimum numeric value of the option. More... | |
auto | to_json (bool with_id=false) const |
Convert object to nlohmann::json. More... | |
Public Attributes | |
bool | autocomplete |
Does this option supports auto completion? More... | |
std::vector< channel_type > | channel_types |
Allowed channel types for channel snowflake id options. More... | |
std::vector< command_option_choice > | choices |
List of choices for multiple choice command. More... | |
std::string | description |
Option description (1-100 chars). More... | |
std::map< std::string, std::string > | description_localizations |
Localisations of command description. More... | |
bool | focused |
Is the user is typing in this field? More... | |
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. More... | |
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. More... | |
std::string | name |
Option name (1-32 chars). More... | |
std::map< std::string, std::string > | name_localizations |
Localisations of command name. More... | |
std::vector< command_option > | options |
An array of sub-commands (options). More... | |
bool | required |
Is this a mandatory parameter? More... | |
command_option_type | type |
Option type (what type of value is accepted). More... | |
command_value | value |
Set only by autocomplete when sent as part of an interaction. More... | |
Protected Member Functions | |
command_option & | fill_from_json_impl (nlohmann::json *j) |
Fill object properties from JSON. More... | |
Friends | |
struct | json_interface< command_option > |
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.
|
default |
Construct a new command option object.
|
virtualdefault |
Destroy the command option object.
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.
t | Option type |
name | Option name |
description | Option description |
required | True if this is a mandatory parameter |
command_option & dpp::command_option::add_channel_type | ( | const channel_type | ch | ) |
Add channel type for option (only for co_channel type options)
ch | type to set |
References dpp::bool_not_null(), dpp::int8_not_null(), dpp::unicode_emoji::o, and dpp::string_not_null().
command_option & dpp::command_option::add_choice | ( | const command_option_choice & | o | ) |
Add a multiple choice option.
o | choice to add |
dpp::logic_exception | command_option is an autocomplete, so choices cannot be added |
Referenced by dpp::commandhandler::add_command().
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.
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) |
command_option & dpp::command_option::add_option | ( | const command_option & | o | ) |
Add a sub-command option.
o | Sub-command 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 |
Fill object properties from JSON.
Fills options recursively.
j | JSON to fill from |
command_option & dpp::command_option::set_auto_complete | ( | bool | autocomp | ) |
Set the auto complete state.
autocomp | True to enable auto completion for this option |
dpp::logic_exception | You attempted to enable auto complete on a command_option that has choices added to it |
References dpp::unicode_emoji::o.
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
max_v | Maximum 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.
max_v | Maximum value |
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
min_v | Minimum 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.
min_v | Minimum value |
References description, name, and type.
|
inlineinherited |
Convert object to nlohmann::json.
with_id | Whether to include the ID or not |
|
friend |
bool dpp::command_option::autocomplete |
Does this option supports auto completion?
std::vector<channel_type> dpp::command_option::channel_types |
Allowed channel types for channel snowflake id options.
std::vector<command_option_choice> dpp::command_option::choices |
List of choices for multiple choice command.
std::string dpp::command_option::description |
Option description (1-100 chars).
Referenced by set_min_value().
std::map<std::string, std::string> dpp::command_option::description_localizations |
Localisations of command description.
Referenced by dpp::interaction::to_json_impl().
bool dpp::command_option::focused |
Is the user is typing in this field?
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.
Referenced by dpp::to_json().
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.
Referenced by dpp::to_json().
std::string dpp::command_option::name |
Option name (1-32 chars).
Referenced by set_min_value().
std::map<std::string, std::string> dpp::command_option::name_localizations |
Localisations of command name.
std::vector<command_option> dpp::command_option::options |
An array of sub-commands (options).
bool dpp::command_option::required |
Is this a mandatory parameter?
command_option_type dpp::command_option::type |
Option type (what type of value is accepted).
Referenced by set_min_value().
command_value dpp::command_option::value |
Set only by autocomplete when sent as part of an interaction.