This commit is contained in:
26
classes/command.ts
Normal file
26
classes/command.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import {
|
||||
SlashCommandBuilder,
|
||||
CommandInteraction,
|
||||
PermissionFlagsBits,
|
||||
} from 'discord.js';
|
||||
|
||||
export interface Component{
|
||||
execute(interaction: unknown): Promise<void>;
|
||||
build(): unknown;
|
||||
};
|
||||
|
||||
export abstract class Command implements Component{
|
||||
abstract get name(): string;
|
||||
abstract get description(): string;
|
||||
abstract execute(interaction: CommandInteraction): Promise<void>;
|
||||
build():
|
||||
SlashCommandBuilder | Omit<
|
||||
SlashCommandBuilder,
|
||||
"addSubcommand" | "addSubcommandGroup"
|
||||
>{
|
||||
return new SlashCommandBuilder()
|
||||
.setName(this.name)
|
||||
.setDescription(this.description)
|
||||
.setDefaultMemberPermissions(PermissionFlagsBits.SendMessages);
|
||||
}
|
||||
};
|
||||
22
classes/extendedclient.ts
Normal file
22
classes/extendedclient.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import {
|
||||
Client,
|
||||
Collection,
|
||||
ClientOptions,
|
||||
} from 'discord.js';
|
||||
|
||||
import {Command} from './command'
|
||||
|
||||
export function isExtendedClient(client: Client): client is ExtendedClient{
|
||||
return (client as ExtendedClient).commands !== undefined;
|
||||
}
|
||||
|
||||
export class ExtendedClient extends Client{
|
||||
public commands: Collection<string, Command>;
|
||||
constructor(
|
||||
opts: ClientOptions,
|
||||
cmds = new Collection<string, Command>()
|
||||
){
|
||||
super(opts);
|
||||
this.commands = cmds;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user