Manager
Reading time:2 min read
The CommandManager is the object that holds together the nyx command system. At a glance:
- Core services: owns the command building blocks, creating defaults in
create()while still allowing targeted injections. - State and deployment sync: add/remove operations update repository and deployer together with rollback on deploy failures, while edit/set keep both layers aligned for bulk updates.
- Interaction routing and execution: resolves incoming interactions to executable commands (including
customIddecoding for component interactions), then runs execute/autocomplete through the executor. - Manager events: emits
CommandAdd,CommandRemove,CommandRun, andCommandAutocompleteso other parts of the system can react to lifecycle and runtime actions.
In practice, this makes it the boundary where command registration, resolution, execution, deployment, subscriptions, events, and runtime metadata are coordinated.
Overriding
Creation
Create a custom command manager by either:
- Extending
DefaultCommandManager. - Implementing
CommandManager.
import { } from '@nyx-discord/djs';
class extends {
public () {
return 'I work!' as ;
}
}Registration
Then you can pass it to your bot:
import { , type } from '@nyx-discord/djs';
const = .((: ) => ({
// ... other options
: new (/** ... */),
}));
const = .();
const result = .();The class is able to infer the type of your custom manager, so accessing any custom method or property will work without errors.
If you ever want to use this custom bot type with your injected manager somewhere else, you can do so via the generic:
import type { , } from '@nyx-discord/djs';
type = < & { : }>;
function (: ) {
const = .();
const result = .();}For readability purposes, we recommend storing the type with the generic in a separate type, like in the example.
Edit on GitHub
Last updated on
