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

The commandhandler class represents a group of commands, prefixed or slash commands with handling functions. More...

#include <commandhandler.h>

Public Member Functions

 commandhandler (class cluster *o, bool auto_hook_events=true, snowflake application_id=0)
 Construct a new commandhandler object. More...
 
 ~commandhandler ()
 Destroy the commandhandler object. More...
 
commandhandlerset_owner (class cluster *o)
 Set the application id after construction. More...
 
commandhandleradd_prefix (const std::string &prefix)
 Add a prefix to the command handler. More...
 
commandhandleradd_command (const std::string &command, const parameter_registration_t &parameters, command_handler handler, const std::string &description="", snowflake guild_id=0)
 Add a command to the command handler. More...
 
void route (const class dpp::message &msg)
 Route a command from the on_message_create function. Call this method from within your on_message_create with the received dpp::message object. More...
 
void route (const class interaction_create_t &event)
 Route a command from the on_interaction_create function. Call this method from your on_interaction_create with the received dpp::interaction_create_t object. More...
 
void reply (const dpp::message &m, command_source source)
 Reply to a command. You should use this method rather than cluster::message_create as the way you reply varies between slash commands and message commands. Note you should ALWAYS reply. Slash commands will emit an ugly error to the user if you do not emit some form of reply within 3 seconds. More...
 

Detailed Description

The commandhandler class represents a group of commands, prefixed or slash commands with handling functions.

Constructor & Destructor Documentation

◆ commandhandler()

dpp::commandhandler::commandhandler ( class cluster o,
bool  auto_hook_events = true,
snowflake  application_id = 0 
)

Construct a new commandhandler object.

Parameters
oOwning cluster to attach to
auto_hook_eventsSet to true to automatically hook the on_interaction_create and on_message events. Only do this if you have no other use for these events than commands that are handled by the command handler (this is usually the case).
application_idThe application id of the bot. If not specified, the class will look within the cluster object and use cluster::me::id instead.

◆ ~commandhandler()

dpp::commandhandler::~commandhandler ( )

Destroy the commandhandler object.

Member Function Documentation

◆ add_command()

commandhandler & dpp::commandhandler::add_command ( const std::string &  command,
const parameter_registration_t parameters,
command_handler  handler,
const std::string &  description = "",
snowflake  guild_id = 0 
)

Add a command to the command handler.

Parameters
commandCommand to be handled. Note that if any one of your prefixes is "/" this will attempt to register a global command using the API and you will receive notification of this command via an interaction event.
handlerHandler function
parametersParameters to use for the command
Returns
commandhandler& reference to self

◆ add_prefix()

commandhandler & dpp::commandhandler::add_prefix ( const std::string &  prefix)

Add a prefix to the command handler.

Parameters
prefixPrefix to be handled by the command handler
Returns
commandhandler& reference to self

◆ reply()

void dpp::commandhandler::reply ( const dpp::message m,
command_source  source 
)

Reply to a command. You should use this method rather than cluster::message_create as the way you reply varies between slash commands and message commands. Note you should ALWAYS reply. Slash commands will emit an ugly error to the user if you do not emit some form of reply within 3 seconds.

Parameters
mmessage to reply with.
interactiontrue if the reply is generated by an interaction

◆ route() [1/2]

void dpp::commandhandler::route ( const class dpp::message msg)

Route a command from the on_message_create function. Call this method from within your on_message_create with the received dpp::message object.

Parameters
msgmessage to parse

◆ route() [2/2]

void dpp::commandhandler::route ( const class interaction_create_t event)

Route a command from the on_interaction_create function. Call this method from your on_interaction_create with the received dpp::interaction_create_t object.

Parameters
eventcommand interaction event to parse

◆ set_owner()

commandhandler & dpp::commandhandler::set_owner ( class cluster o)

Set the application id after construction.

Parameters
oOwning cluster to attach to
D++ Library version 10.0.29D++ Library version 10.0.28D++ Library version 10.0.27D++ Library version 10.0.26D++ Library version 10.0.25D++ Library version 10.0.24D++ Library version 10.0.23D++ Library version 10.0.22D++ Library version 10.0.21D++ Library version 10.0.20D++ Library version 10.0.19D++ Library version 10.0.18D++ Library version 10.0.17D++ Library version 10.0.16D++ Library version 10.0.15D++ Library version 10.0.14D++ Library version 10.0.13D++ Library version 10.0.12D++ Library version 10.0.11D++ Library version 10.0.10D++ Library version 10.0.9D++ Library version 10.0.8D++ Library version 10.0.7D++ Library version 10.0.6D++ Library version 10.0.5D++ Library version 10.0.4D++ Library version 10.0.3D++ Library version 10.0.2D++ Library version 10.0.1D++ Library version 10.0.0D++ Library version 9.0.19D++ Library version 9.0.18D++ Library version 9.0.17D++ Library version 9.0.16D++ Library version 9.0.15D++ Library version 9.0.14D++ 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