️💼 Command Manager
The CommandManager
is the object that holds together the nyx event system.
It consists of:
CommandCustomIdCodec
: De/serializes commands names to/from customId strings, useful for creating message components that will trigger commands.CommandResolver
: Resolves the command data that a given command interaction refers to.CommandExecutor
: Executes command objects, checking itsCommandMiddlewareList
and passing any errors to itsErrorHandler
.CommandRepository
: Stores all the currently registered commands and their command application mappings. It's also responsible for registering commands at Discord.CommandSubscriptionsContainer
: Stores the 📩 Event Subscribers that are subscribed to the 👂 Client event bus to listen for command interactions.EventBus
: An 📣 Event Bus that emits command related events.
As well as methods to interact with them.
👷 Creation
You can create a custom command manager by either:
- Extending
DefaultCommandManager
from@nyx-discord/framework
(recommended). - Implementing
CommandManager
from@nyx-discord/core
.
Then you can pass it to your bot:
class MyCommandManager extends DefaultCommandManager {
public myCustomPublicMethod() {}
}
const myBot = Bot.create((bot: NyxBot) => ({
// ...
events: new MyCommandManager(/** ... */),
}));
myBot.getCommandManager().myCustomPublicMethod() // works!
The Bot
class is able to infer the type of your custom manager via generics, so accessing any custom public method or
property will work without errors.