In a program with many different
ApplicationCommandTargets, how do you go about registering them with the central
ApplicationCommandManager? I’ve never found a way that feels satisfactory.
(I’m talking about
There two obvious choices are:
- Register the targets in their respective constructors;
- Register the targets in the constructor of the class that holder the
If you choose 1, then you end up re-registering the class every time you create a new instance of the class. In a class which you create and destroy often, this feels a bit gratuitous. (You also have to take a reference of the parent class which holds the
ApplicationCommandManager, which seems like bad practice.)
If you choose 2, then you find yourself having to register a class that hasn’t been created yet. So then you have to create temporary objects, and wrestle with constructors that expect certain input that isn’t easily available.
Ideally I would want to register commands using a static method, since the commands typically don’t relate to the internal state of the object. But I can’t see any way of doing this, as the relevant methods in
ApplicationCommandTarget are virtual.
Is there a third way? If not, is there a way of approaching 1 or 2 that makes them more viable?