commandbot
Version:
A framework that helps you create your own Discord bot easier.
151 lines (150 loc) • 3.61 kB
JavaScript
/**
* Error indicating that a caller doesn't have enough permissions to execute a command
* @class
* @extends {Error}
*/
export class PermissionsError extends Error {
/**
* Command that user wanted and failed to invoke
* @type {Command}
* @private
* @readonly
*/
command;
/**
* User that doesn't have the permissions
* @type {?GuildMember}
* @private
* @readonly
*/
user;
/**
* @constructor
* @param {Command} command - command that user wanted and failed to invoke
* @param {?GuildMember} [user] - user that doesn't have the permissions
*/
constructor(command, user) {
super();
this.command = command;
this.user = user || null;
}
/**
* Converts error object to user-readable message
* @returns {string} Formatted error message
* @public
*/
toString() {
return `User ${this.user?.user.tag} doesn't have enough permissions to run "${this.command.name}" command`;
}
}
/**
* Error indicating that an input value cannot be converted to a expected type
* @class
* @extends {TypeError}
*/
export class ParameterTypeError extends TypeError {
/**
* Value converted to a string
* @type {string}
* @private
* @readonly
*/
stringContent;
/**
* Expected type
* @type {ParameterType}
* @private
* @readonly
*/
type;
/**
* @constructor
* @param {ParameterResolvable} s - value with an invalid type
* @param {ParameterType} type - expected type
*/
constructor(s, type) {
super();
this.stringContent = s?.toString() ?? "";
this.type = type;
}
/**
* Converts error object to user-readable message
* @returns {string} Formatted error message
* @public
*/
toString() {
return `Parameter "${this.stringContent}" cannot be converted to ${this.type}`;
}
}
/**
* Error indicating that a required parameter is missing in the request
* @class
* @extends {ReferenceError}
*/
export class MissingParameterError extends ReferenceError {
/**
* Missing parameter object
* @type {Parameter<any>}
* @private
* @readonly
*/
argument;
/**
* @constructor
* @param {Parameter<any>} a - missing parameter object
*/
constructor(a) {
super();
this.argument = a;
}
/**
* Converts error object to user-readable message
* @returns {string} Formatted error message
* @public
*/
toString() {
return `Your request is missing a "${this.argument.name}" parameter which is not optional`;
}
}
/**
* Object indicating command execution success
* @class
*/
export class OperationSuccess {
/**
* Command that succeeded
* @type {Command}
* @public
* @readonly
*/
command;
/**
* @constructor
* @param {Command} c - command that succeeded
*/
constructor(c) {
this.command = c;
}
}
/**
* Error thrown when there is no command with the given name
* @class
* @extends {Error}
*/
export class CommandNotFound extends Error {
/**
* User query
* @type {string}
* @public
* @readonly
*/
query;
/**
* @constructor
* @param {?string} [q] - user query
*/
constructor(q) {
super("Command not found");
this.query = q;
}
}