MessageUsageError
class in meocord/common Since 4.1.0
class MessageUsageError extends ErrorThe 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
@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
| Name | Type | Description |
|---|---|---|
usage | string | The command as the user should type it, such as |
issues | MessageUsageIssue[] | Each thing wrong, in the order of the command's params. |
options? | {
serverOnly?: boolean
dmOnly?: boolean
quiet?: boolean
} |
|
options.serverOnly? | boolean | |
options.dmOnly? | boolean | |
options.quiet? | boolean |
dmOnly
readonly dmOnly: booleanWhether the command works only in direct messages and the message was sent in a server.
issues
readonly issues: MessageUsageIssue[]quiet
readonly quiet: booleanWhether the message used no prefix or mention, so it may be ordinary chat, which is not answered.
serverOnly
readonly serverOnly: booleanWhether the command works only in a server and the message was sent elsewhere.
usage
readonly usage: stringSee also
- MessageHandler
- translateError
- Message commands