@yariplus The plugin needs to export the method you want to use within the main script. Using any of the ways above, you can use exports of non-main modules within that plugin.
Checking whether any plugin is enabled or not would be a task to check via NodeBB modules. Directly attempting to access a plugins exports however should not depend on the internal structure of NodeBB in my opinion.
If you want to call a plugins exported attributes only iff the plugin is enabled, your way seems to be good though.
I guess I'd still use
// would be neat if NodeBB provides a function for this ;-) Accessing NodeBB's non-function attributes directly seems somehow wrong to me
// proposal: plugins.isEnabled("my-plugin") if nothing alike exists already
if (plugins.libraries.hasOwnProperty("my-plugin")) {
require("my-plugin").function();
}
since it clearly states where the functions source code lies.