private void AddSubcommand(BaseCommandDelegate <TSender> command, string[] names)
 {
     foreach (string name in names)
     {
         if (subcommands.ContainsKey(name))
         {
             throw new CommandRegistrationException($"Failed to register command \"{Name} {name}\" because it is a duplicate.");
         }
         subcommands[name] = command;
     }
     subcommandList.Add(command);
 }
        public CommandGroupDelegate(Context <TSender> context, string mainName, string[] allNames, Type command) : base(context, mainName, allNames)
        {
            foreach (CustomAttribute attribute in command.GetCustomAttributes <CustomAttribute>(true))
            {
                customAttributes[attribute.GetType()] = attribute;
            }

            bool anySubcommands = false;

            foreach (MethodInfo subcommand in command.GetMethods())
            {
                if (subcommand.GetCommandNames <Command>() != null)
                {
                    throw new CommandRegistrationException($"Unexpected Command attribute in {command.Name}.{subcommand.Name}.");
                }
                string[] subcommandNames = subcommand.GetCommandNames <SubCommand>();
                if (subcommandNames != null)
                {
                    anySubcommands = true;
                    bool isDefault = subcommand.GetSubCommandIsDefault();

                    var newSubcommand = new BaseCommandDelegate <TSender>(Context, isDefault ? Name : $"{Name} {subcommandNames[0]}", subcommandNames, subcommandNames[0], subcommand);

                    // Check if it's the default command
                    if (isDefault)
                    {
                        if (defaultCommand != null)
                        {
                            throw new CommandRegistrationException($"There are two or more default subcommands in {command.Name}.");
                        }
                        defaultCommand = newSubcommand;
                    }

                    AddSubcommand(newSubcommand, subcommandNames);
                }
            }
            if (!anySubcommands)
            {
                throw new CommandRegistrationException($"{command.Name} must contain at least one subcommand.");
            }
        }