diff --git a/src/Error.ts b/src/Error.ts new file mode 100644 index 0000000..9e8bc60 --- /dev/null +++ b/src/Error.ts @@ -0,0 +1,40 @@ +import { Command } from "./Command.js"; +import { GuildMember } from "discord.js"; +import { Argument, ArgumentType } from "Arguments.js"; + +export class PermissionsError extends Error { + private command: Command; + private user: GuildMember | null; + constructor(command: Command, user?: GuildMember | null) { + super(); + this.command = command; + this.user = user || null; + } + toString() { + return `User ${this.user?.user.tag} doesn't have enough permissions to run "${this.command.name}" command`; + } +} + +export class ArgumentTypeError extends TypeError { + private stringContent: string; + private type: ArgumentType; + constructor(s: string, type: ArgumentType) { + super(); + this.stringContent = s; + this.type = type; + } + toString() { + `Argument ${this.stringContent} cannot be converted to ${this.type}`; + } +} + +export class MissingArgumentError extends ReferenceError { + private argument: Argument; + constructor(a: Argument) { + super(); + this.argument = a; + } + toString() { + return `${this.argument.name}: Argument not optional`; + } +}