Skip to content
GitHub

MessageUsageError

class in meocord/common Since 4.1.0

class MessageUsageError extends Error

The error raised when a message names a command but does not fit its pattern, which the user is told.

Catch it in a filter to answer a misuse in the app's own words or language. Without one, the built-in fallback replies with the command's usage and the issues, and deletes the reply after @MeoCord({ messages: { deleteUsageRepliesAfter } }) seconds.

Examples

TypeScript
@Catch(MessageUsageError)
export class UsageFilter implements ExceptionFilter<MessageUsageError> {
  async catch(error: MessageUsageError, context: ExecutionContext) {
    if (!error.quiet) await context.getMessage()?.reply(`Try \`${error.usage}\``)
  }
}

Members

constructor

new MessageUsageError(
  usage: string,
  issues: MessageUsageIssue[],
  options?: {
    serverOnly?: boolean
    dmOnly?: boolean
    quiet?: boolean
  },
)

Parameters

NameTypeDescription
usagestring

The command as the user should type it, such as !ban <target> [reason…], or one line per subcommand for a message that names only their parent.

issuesMessageUsageIssue[]

Each thing wrong, in the order of the command's params.

options?{ serverOnly?: boolean dmOnly?: boolean quiet?: boolean }

serverOnly or dmOnly for a command sent where it does not work, and quiet for a message that used no prefix or mention.

options.serverOnly?boolean
options.dmOnly?boolean
options.quiet?boolean

dmOnly

readonly dmOnly: boolean

Whether the command works only in direct messages and the message was sent in a server.

issues

readonly issues: MessageUsageIssue[]

quiet

readonly quiet: boolean

Whether the message used no prefix or mention, so it may be ordinary chat, which is not answered.

serverOnly

readonly serverOnly: boolean

Whether the command works only in a server and the message was sent elsewhere.

usage

readonly usage: string

See also