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

Creating a command register

SeanOMik edited this page Sep 3, 2020 · 4 revisions

As your bot grows, you may think it is annoying to construct all of your commands in the main function, luckily we have a solution to this problem called a command register.

  • Create a new header file called command_register.h
#ifndef BOT_COMMAND_REGISTER_H
#define BOT_COMMAND_REGISTER_H

/* include your commands here */

#include "commands/administration/command_ban.h"
#include "commands/administration/command_kick.h"

#include "commands/command_handler.h"

namespace my_discpp_bot {
    namespace register{
        namespace { 
            BanCommand* ban_command;
            KickCommand* kick_command;
        }

        void RegisterCommands() {
            ban_command = new BanCommand();
            kick_command = new KickCommand();
        }
    }
}

#endif
  • Now in your main function call my_discpp_bot::register::RegisterCommands() to register your commands without the spam in the main function.