-
Notifications
You must be signed in to change notification settings - Fork 2
Creating a group command
Note: Only available on command-system branch
Group commands are useful when you have a command that takes multiple arguments to run. For instance, a good usage of a group command would be for something like base64
in which you need to include both encode
and decode
as required arguments. Group commands allow you to automatically parse arguments instead of manually parsing with ctx.arguments
, they also allow for multiple functionalities in a given command.
First you need to create a simple command that needs subcommands. In this example, I will be using a role group command, this command will allow me to list the roles in a given server AND allow me to see crucial information about each role.
Start off with your command header CommandRole.h
#ifndef EXAMPLE_ROLE_GROUP_COMMAND_H //these are include guards
#define EXAMPLE_ROLE_GROUP_COMMAND_H
#include <discpp/command.h>
#include <discpp/context.h>
class RoleCommand : public discpp::Command {
public:
RoleCommand(); // create our constructor
virtual bool CanRun(discpp::Context ctx) override; // create our preconditions, we only want this command executing in guilds
virtual void CommandBody(discpp::Context ctx) override; // create our command body
};
class RoleInfoCommand : public discpp::SubCommand {
public:
RoleInfoCommand();
virtual bool CanRun(discpp::Context ctx) override;
virtual void CommandBody(discpp::Context ctx) override;
};
class RoleListCommand : public discpp::SubCommand {
public:
RoleListCommand();
virtual bool CanRun(discpp::Context ctx) override;
virtual void CommandBody(discpp::Context ctx) override;
};
#endif
Next we will create our source file for this new command
CommandRole.cpp
#include "CommandRole.h"
RoleCommand::RoleCommand() : public discpp::Command("role") {
}```