Error classes

This commit is contained in:
mmacierzanka committed 2021-08-02 22:02:33 +02:00
1 parent 8bd3dbd8d2
commit 781472a200
1 file changed
+40
+40
View File
@@ -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`;
}
}