Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Creating a group command

SeanOMik edited this page Sep 3, 2020 · 3 revisions

Note: Only available on command-system branch

Why use a group command over normal commands?

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.

Starting off

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") { 

}```