Skip to content

Command Structure

Extending the Command class

Extending the class is easy and you can add as many properties as you like, just don’t touch what is already in the Command class.

my.command.ts
export interface
interface MyOptions
MyOptions
extends
(alias) interface CommandOptions
import CommandOptions

Represents the options for creating a command

CommandOptions
{
MyOptions.code: () => unknown
code
: (/* Type definitions of your arguments */) => unknown
}
export class
class MyCommand<Options extends MyOptions>
MyCommand
<
function (type parameter) Options in MyCommand<Options extends MyOptions>
Options
extends
interface MyOptions
MyOptions
> extends
class Command<Options extends CommandOptions>

Represents an abstract class of a command.

This is intended to be extended with other things including the function to execute the command, i.e. code(...), exec(...), etc.

Command
<
function (type parameter) Options in MyCommand<Options extends MyOptions>
Options
> {
MyCommand<Options extends MyOptions>.code: () => unknown
code
: (/* Type definitions of your arguments */) => unknown;
constructor(
options: Options extends MyOptions
options
:
function (type parameter) Options in MyCommand<Options extends MyOptions>
Options
) {
super(
options: Options extends MyOptions
options
);
this.
MyCommand<Options extends MyOptions>.code: () => unknown
code
=
options: Options extends MyOptions
options
.
MyOptions.code: () => unknown
code
;
}
}

As you can see, we set code as a function, with this logic you can add as many properties and functions as you like.

Your First Command

Just now we will see how you can use your MyCommand class.

my.first.command.ts
export default new
constructor MyCommand<{
data: {
name: string;
description: string;
};
code(): void;
}>(options: {
data: {
name: string;
description: string;
};
code(): void;
}): MyCommand<{
data: {
name: string;
description: string;
};
code(): void;
}>
MyCommand
({
data: {
name: string;
description: string;
}
data
: {
name: string
name
: 'test',
description: string
description
: 'Just a test command'
},
function code(): void
code
(/* Command's params */) { /* Command's code */ }
});