Bot / structs/handlers/CommandHandler / CommandHandler
structs/handlers/CommandHandler.CommandHandler
The base structure for handlers.
Handlers are used to manage modules, which are abstract classes that must be extended to define a certain functionality. Handlers are responsible for importing modules from files and storing them within a collection for future reference.
-
Handler<BaseCommand<ApplicationCommandType>>↳
CommandHandler
• new CommandHandler(client)
Initializes a new Handler instance.
| Name | Type | Description |
|---|---|---|
client |
Client<boolean> |
The instantiated Discord client. |
src/structs/handlers/CommandHandler.ts:29
• Readonly client: Client<boolean>
The Discord client.
A reference to the instantiated Discord client.
src/structs/handlers/Handler.ts:45
• Readonly directory: string = paths.COMMANDS
The base directory that contains the desired modules.
When importing commands, the handler will look in this directory for commands to import, recursively looking in subdirectories.
src/structs/handlers/CommandHandler.ts:17
• Readonly modules: Map<string, BaseCommand<ApplicationCommandType>>
The collection of modules that the handler manages.
References all modules that have been initialized by the handler, stored within a collection for future reference.
src/structs/handlers/Handler.ts:53
• Readonly reference: AbstractClass<BaseCommand<ApplicationCommandType>, any[]> = BaseCommand
The reference to the abstract class that the handler manages.
src/structs/handlers/CommandHandler.ts:22
▸ import(path): BaseCommand<ApplicationCommandType>
Imports and initializes a module from a file.
This method implements the logic used for initializing a module from a file, given a path, the method attempts to import and initialize a module from the file.
Note that when importing a module, this method only looks at the script's default export.
| Name | Type | Description |
|---|---|---|
path |
string |
The path to import the module from. |
BaseCommand<ApplicationCommandType>
The initialized module.
src/structs/handlers/Handler.ts:77
▸ inherits(object): object is Function
Determines whether if the provided object is a valid module.
A helper method that determines whether if the provided object is an instantiable class that extends the abstract class that the handler manages.
This method is used to determine whether if a file correctly exports an instance of the expected class.
| Name | Type | Description |
|---|---|---|
object |
unknown |
The object to check. |
object is Function
Whether if the object is a valid module.
src/structs/handlers/Handler.ts:163
▸ register(path): BaseCommand<ApplicationCommandType>
Registers a module within the handler.
This method will register a module from the specified path, initializing it and storing it within the handler's collection of modules.
| Name | Type | Description |
|---|---|---|
path |
string |
The path to register the module at. |
BaseCommand<ApplicationCommandType>
The registered module.
src/structs/handlers/Handler.ts:131
▸ registerAll(directory?): void
Registers all modules from the provided directory.
This method will recursively import all modules from the specified directory, initializing them and storing them within the handler's collection of modules.
| Name | Type | Description |
|---|---|---|
directory |
string |
The directory to register modules from. |
void