D++ (DPP)
C++ Discord API Bot Library
dpp::slashcommand Class Reference

Represents an application command, created by your bot either globally, or on a guild. More...

+ Inheritance diagram for dpp::slashcommand:
+ Collaboration diagram for dpp::slashcommand:

Public Member Functions

 slashcommand ()
 Construct a new slashcommand object. More...
 
 slashcommand (const std::string &_name, const std::string &_description, const dpp::snowflake _application_id)
 Construct a new slashcommand object. More...
 
 slashcommand (const std::string &_name, const slashcommand_contextmenu_type _type, const dpp::snowflake _application_id)
 Construct a new slashcommand object. More...
 
virtual ~slashcommand ()=default
 Destroy the slashcommand object. More...
 
slashcommandadd_localization (const std::string &language, const std::string &_name, const std::string &_description="")
 Add a localisation for this slash command. More...
 
slashcommandset_dm_permission (bool dm)
 Set the dm permission for the command. More...
 
slashcommandset_nsfw (bool is_nsfw)
 Set whether the command should be age-restricted or not. More...
 
slashcommandset_default_permissions (uint64_t defaults)
 Set the default permissions of the slash command. More...
 
slashcommandadd_option (const command_option &o)
 Add an option (parameter) More...
 
slashcommandset_type (slashcommand_contextmenu_type _type)
 Set the type of the slash command (only for context menu entries) More...
 
slashcommandset_name (const std::string &n)
 Set the name of the command. More...
 
slashcommandset_description (const std::string &d)
 Set the description of the command. More...
 
slashcommandset_application_id (snowflake i)
 Set the application id of the command. More...
 
slashcommandadd_permission (const command_permission &p)
 Adds a permission to the command. More...
 
slashcommanddisable_default_permissions ()
 Disable default permissions, command will be unusable unless permissions are overridden with add_permission and dpp::guild_command_edit_permissions. More...
 
std::string get_mention () const
 Return a ping/mention for the slash command. More...
 
constexpr double get_creation_time () const noexcept
 Get the creation time of this object according to Discord. More...
 
constexpr bool operator== (const managed &other) const noexcept
 Comparison operator for comparing two managed objects by id. More...
 
constexpr bool operator!= (const managed &other) const noexcept
 Comparison operator for comparing two managed objects by id. More...
 
slashcommandfill_from_json (nlohmann::json *j)
 Convert object from nlohmann::json. More...
 
auto to_json (bool with_id=false) const
 Convert object to nlohmann::json. More...
 
std::string build_json (bool with_id=false) const
 Convert object to json string. More...
 

Public Attributes

snowflake application_id
 Application id (usually matches your bots id) More...
 
slashcommand_contextmenu_type type
 Context menu type, defaults to dpp::ctxm_chat_input. More...
 
std::string name
 Command name (1-32 chars) More...
 
std::string description
 Command description (1-100 chars) More...
 
std::vector< command_optionoptions
 Command options (parameters) More...
 
bool default_permission
 Whether the command is enabled by default when the app is added to a guild. This has no effect as the default_member_permissions value is used instead. More...
 
std::vector< command_permissionpermissions
 command permissions More...
 
snowflake version
 autoincrementing version identifier updated during substantial record changes More...
 
std::map< std::string, std::string > name_localizations
 Localisations of command name. More...
 
std::map< std::string, std::string > description_localizations
 Localisations of command description. More...
 
permission default_member_permissions
 The default permissions of this command on a guild. D++ defaults this to dpp::p_use_application_commands. More...
 
bool dm_permission
 True if this command should be allowed in a DM D++ defaults this to false. Cannot be set to true in a guild command, only a global command. More...
 
bool nsfw
 Indicates whether the command is age-restricted. Defaults to false. More...
 
snowflake id = {}
 Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID, and an incrementing value. Only the timestamp is relevant to us as useful metadata. More...
 

Protected Member Functions

slashcommandfill_from_json_impl (nlohmann::json *j)
 Fill object properties from JSON. More...
 
json to_json_impl (bool with_id=false) const
 Build a json for this object. More...
 

Friends

struct json_interface< slashcommand >
 

Detailed Description

Represents an application command, created by your bot either globally, or on a guild.

Constructor & Destructor Documentation

◆ slashcommand() [1/3]

dpp::slashcommand::slashcommand ( )

Construct a new slashcommand object.

◆ slashcommand() [2/3]

dpp::slashcommand::slashcommand ( const std::string &  _name,
const std::string &  _description,
const dpp::snowflake  _application_id 
)

Construct a new slashcommand object.

Parameters
_nameCommand name
_descriptionCommand description
_application_idApplication id (usually the bot's user id)

◆ slashcommand() [3/3]

dpp::slashcommand::slashcommand ( const std::string &  _name,
const slashcommand_contextmenu_type  _type,
const dpp::snowflake  _application_id 
)

Construct a new slashcommand object.

Parameters
_nameCommand name
_typeContext menu type
_application_idApplication id (usually the bot's user id)

◆ ~slashcommand()

virtual dpp::slashcommand::~slashcommand ( )
virtualdefault

Destroy the slashcommand object.

Member Function Documentation

◆ add_localization()

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

Add a localisation for this slash command.

See also
https://discord.com/developers/docs/reference#locales
Parameters
languageName of language, see the list of locales linked to above
_namename of slash command in the specified language
_descriptiondescription of slash command in the specified language (optional)
Returns
slashcommand& reference to self for chaining of calls

◆ add_option()

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

Add an option (parameter)

Parameters
ooption (parameter) to add
Returns
slashcommand& reference to self for chaining of calls

◆ add_permission()

slashcommand& dpp::slashcommand::add_permission ( const command_permission p)

Adds a permission to the command.

Parameters
ppermission to add
Returns
slashcommand& reference to self for chaining of calls
Deprecated:
Discord discourage use of this value and instead you should use default_member_permissions.

◆ build_json()

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

Convert object to json string.

Parameters
with_idWhether 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

◆ disable_default_permissions()

slashcommand& dpp::slashcommand::disable_default_permissions ( )

Disable default permissions, command will be unusable unless permissions are overridden with add_permission and dpp::guild_command_edit_permissions.

Returns
slashcommand& reference to self for chaining of calls
Deprecated:
Discord discourage use of this value and instead you should use default_member_permissions.

◆ fill_from_json()

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

Convert object from nlohmann::json.

Parameters
jnlohmann::json object
Returns
T& Reference to self for fluent calling

◆ fill_from_json_impl()

slashcommand& dpp::slashcommand::fill_from_json_impl ( nlohmann::json *  j)
protected

Fill object properties from JSON.

Parameters
jJSON to fill from
Returns
slashcommand& Reference to self

◆ get_creation_time()

constexpr double dpp::managed::get_creation_time ( ) const
inlineconstexprnoexceptinherited

Get the creation time of this object according to Discord.

Returns
double creation time inferred from the snowflake ID. The minimum possible value is the first second of 2015.

◆ get_mention()

std::string dpp::slashcommand::get_mention ( ) const

Return a ping/mention for the slash command.

Returns
std::string mention. e.g. </airhorn:816437322781949972>
Note
If you want a mention for a subcommand or subcommand group, you can use dpp::utility::slashcommand_mention

◆ operator!=()

constexpr bool dpp::managed::operator!= ( const managed other) const
inlineconstexprnoexceptinherited

Comparison operator for comparing two managed objects by id.

Parameters
otherOther object to compare against
Returns
true objects are not the same id
false objects are the same id

◆ operator==()

constexpr bool dpp::managed::operator== ( const managed other) const
inlineconstexprnoexceptinherited

Comparison operator for comparing two managed objects by id.

Parameters
otherOther object to compare against
Returns
true objects are the same id
false objects are not the same id

◆ set_application_id()

slashcommand& dpp::slashcommand::set_application_id ( snowflake  i)

Set the application id of the command.

Parameters
iapplication id
Returns
slashcommand& reference to self for chaining of calls

◆ set_default_permissions()

slashcommand& dpp::slashcommand::set_default_permissions ( uint64_t  defaults)

Set the default permissions of the slash command.

Parameters
defaultsdefault permissions to set. This is a permission bitmask of bits from dpp::permissions
Note
You can set it to 0 to disable the command for everyone except admins by default
Returns
slashcommand& reference to self for chaining of calls

◆ set_description()

slashcommand& dpp::slashcommand::set_description ( const std::string &  d)

Set the description of the command.

Parameters
ddescription
Note
The maximum length of a command description is 100 UTF-8 codepoints. If your command description is longer than this, it will be truncated.
Returns
slashcommand& reference to self for chaining of calls

◆ set_dm_permission()

slashcommand& dpp::slashcommand::set_dm_permission ( bool  dm)

Set the dm permission for the command.

Parameters
dmtrue to allow this command in dms
Returns
slashcommand& reference to self for chaining of calls

◆ set_name()

slashcommand& dpp::slashcommand::set_name ( const std::string &  n)

Set the name of the command.

Parameters
nname of command
Note
The maximum length of a command name is 32 UTF-8 codepoints. If your command name is longer than this, it will be truncated. The command name will be set to lowercase when the type is the default dpp::ctxm_chat_input.
Returns
slashcommand& reference to self for chaining of calls

◆ set_nsfw()

slashcommand& dpp::slashcommand::set_nsfw ( bool  is_nsfw)

Set whether the command should be age-restricted or not.

Parameters
is_nsfwtrue if the command should be age-restricted
Returns
slashcommand& reference to self for chaining of calls

◆ set_type()

slashcommand& dpp::slashcommand::set_type ( slashcommand_contextmenu_type  _type)

Set the type of the slash command (only for context menu entries)

Parameters
_typeType of context menu entry this command represents
Note
If the type is dpp::ctxm_chat_input, the command name will be set to lowercase.
Returns
slashcommand& reference to self for chaining of calls

◆ to_json()

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

Convert object to nlohmann::json.

Parameters
with_idWhether 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

◆ to_json_impl()

json dpp::slashcommand::to_json_impl ( bool  with_id = false) const
protected

Build a json for this object.

Parameters
with_idTrue if to include the ID in the JSON
Returns
json JSON object

Friends And Related Function Documentation

◆ json_interface< slashcommand >

friend struct json_interface< slashcommand >
friend

Member Data Documentation

◆ application_id

snowflake dpp::slashcommand::application_id

Application id (usually matches your bots id)

◆ default_member_permissions

permission dpp::slashcommand::default_member_permissions

The default permissions of this command on a guild. D++ defaults this to dpp::p_use_application_commands.

Note
You can set it to 0 to disable the command for everyone except admins by default

◆ default_permission

bool dpp::slashcommand::default_permission

Whether the command is enabled by default when the app is added to a guild. This has no effect as the default_member_permissions value is used instead.

Deprecated:
Discord discourage use of this value and instead you should use slashcommand::default_member_permissions.

◆ description

std::string dpp::slashcommand::description

Command description (1-100 chars)

◆ description_localizations

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

Localisations of command description.

◆ dm_permission

bool dpp::slashcommand::dm_permission

True if this command should be allowed in a DM D++ defaults this to false. Cannot be set to true in a guild command, only a global command.

◆ id

snowflake dpp::managed::id = {}
inherited

Unique ID of object set by Discord. This value contains a timestamp, worker ID, internal server ID, and an incrementing value. Only the timestamp is relevant to us as useful metadata.

◆ name

std::string dpp::slashcommand::name

Command name (1-32 chars)

◆ name_localizations

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

Localisations of command name.

◆ nsfw

bool dpp::slashcommand::nsfw

Indicates whether the command is age-restricted. Defaults to false.

◆ options

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

Command options (parameters)

◆ permissions

std::vector<command_permission> dpp::slashcommand::permissions

command permissions

Deprecated:
Discord discourage use of this value and instead you should use default_member_permissions.

◆ type

slashcommand_contextmenu_type dpp::slashcommand::type

Context menu type, defaults to dpp::ctxm_chat_input.

◆ version

snowflake dpp::slashcommand::version

autoincrementing version identifier updated during substantial record changes

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