Skip to content

Latest commit

 

History

History
263 lines (147 loc) · 7.26 KB

File metadata and controls

263 lines (147 loc) · 7.26 KB

Bot / structs/handlers/CommandHandler / CommandHandler

Class: 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.

Hierarchy

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new CommandHandler(client)

Initializes a new Handler instance.

Parameters

Name Type Description
client Client<boolean> The instantiated Discord client.

Overrides

Handler.constructor

Defined in

src/structs/handlers/CommandHandler.ts:29

Properties

client

Readonly client: Client<boolean>

The Discord client.

A reference to the instantiated Discord client.

Inherited from

Handler.client

Defined in

src/structs/handlers/Handler.ts:45


directory

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.

Overrides

Handler.directory

Defined in

src/structs/handlers/CommandHandler.ts:17


modules

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.

Inherited from

Handler.modules

Defined in

src/structs/handlers/Handler.ts:53


reference

Readonly reference: AbstractClass<BaseCommand<ApplicationCommandType>, any[]> = BaseCommand

The reference to the abstract class that the handler manages.

Overrides

Handler.reference

Defined in

src/structs/handlers/CommandHandler.ts:22

Methods

import

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.

Parameters

Name Type Description
path string The path to import the module from.

Returns

BaseCommand<ApplicationCommandType>

The initialized module.

Inherited from

Handler.import

Defined in

src/structs/handlers/Handler.ts:77


inherits

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.

Parameters

Name Type Description
object unknown The object to check.

Returns

object is Function

Whether if the object is a valid module.

Inherited from

Handler.inherits

Defined in

src/structs/handlers/Handler.ts:163


register

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.

Parameters

Name Type Description
path string The path to register the module at.

Returns

BaseCommand<ApplicationCommandType>

The registered module.

Inherited from

Handler.register

Defined in

src/structs/handlers/Handler.ts:131


registerAll

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.

Parameters

Name Type Description
directory string The directory to register modules from.

Returns

void

Inherited from

Handler.registerAll

Defined in

src/structs/handlers/Handler.ts:101