MessageCommandOptions
interface in meocord/interface Since 4.1.0
interface MessageCommandOptionsHow message commands start and match across the app, set in @MeoCord({ messages }).
Use it to give @MessageHandler patterns a prefix, accept a mention of the bot in its place, and add param
types of the app's own. A handler sets its own start and case with MessageHandlerOptions.
Examples
@Controller()
class DiceController {
@MessageHandler('roll {sides:int}')
async roll(message: Message, { sides }: { sides: number }) {
await message.reply(String(1 + Math.floor(Math.random() * sides)))
}
}
@MeoCord({
controllers: [DiceController],
clientOptions: { intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] },
// !roll 20, or @Bot roll 20; a usage reply stays 30 seconds
messages: { prefix: '!', mention: true, deleteUsageRepliesAfter: 30 },
})
class App {}Members
prefix
prefix?:
| MessagePrefix
| ((
message: Message,
) =>
| MessagePrefix
| null
| undefined
| Promise<MessagePrefix | null | undefined>)What a message starts with to reach a patterned handler: a prefix, a list of them, or a function
of the message returning them, such as a server's own prefix. Without one, a pattern matches the
message as it is. Where a function finds none, returning an empty list, undefined or null, no prefix
starts a command for that message, though a mention still does when mention is on; only '' takes it as it
is. A handler's own prefix replaces it.
mention
mention?: boolean | 'only'Also accepts a mention of the bot, <@id> or <@!id>, where a prefix goes. 'only' accepts nothing else
in a server, neither a prefix nor the message as it is, so a server's messages reach commands only when they
mention the bot, which Discord delivers with their text even without the privileged MessageContent intent. A
direct message, addressed to the bot already, starts as usual: after the prefix, or as it is without one.
Default: false
caseSensitive
caseSensitive?: booleanMatches the prefix, a pattern's literal words, its choice words and its flag names in the case written. A text param keeps the case the user typed either way.
Default: false
types
types?: Record<string, MessageParamType>Param types of the app's own, used in patterns as {name:type} by their key here. Declare each in
MessageParamTypes as well, so a handler's params are typed from its pattern.
deleteUsageRepliesAfter
deleteUsageRepliesAfter?: numberHow long a reply showing a command's usage, or a guard's or validation's reason, stays before it is deleted, in
seconds. 0 keeps it.
Default: 10
replyEmoji
replyEmoji?: booleanBegins every text reply MeoCord sends to a message with the theme's emojis.warning: a command's usage, a
guard's or validation's reason, a UserError's message, an @On listener's of a message event included, and the
direct messages dmOnError and dmOnCooldown send. The built-in help's reply begins with emojis.info instead.
The emoji is the call's resolved theme's, so it follows @UseTheme and themeFor.
Default: false
dmOnError
dmOnError?: booleanTells the author of a message command, in a direct message, when it fails with an error no filter handled,
naming the command, the channel and the server. The error is logged as without it, and nothing is said in the
channel: a message cannot be answered privately there. A command sent in a direct message is answered in it.
The text is meocord.dm.error, around what the fallback answers the error with, such as the cooldown store's
meocord.cooldown.storeDown, in the server's language. A member whose direct messages are closed is not told.
Only patterned handlers are answered, not a listener for every message. A command refused because the cooldown
store failed is told once per outage per author.
Default: false
dmOnCooldown
dmOnCooldown?: booleanTells the author of a message command, in a direct message, when a @Cooldown refuses it, with how long to
wait, once per wait: retrying before it ends sends nothing more. The notice is counted in the app's cooldown
store, so it holds across shards with a shared store. The text is meocord.dm.cooldown, around the cooldown's
own wait text, in the server's language. A command sent in a direct message is answered in it, and a member
whose direct messages are closed is not told. Only patterned handlers are answered.
Default: false
help
help?: boolean | MessageHelpOptionsAnswers !help with the message commands that work here, leaving out hidden ones and those with guards of their
own, since help runs only the app's guards, and !help <command> with the one it names, listed or not, from the
description each handler gives. true uses the word help; { command, aliases } names other words. It
answers only after a prefix or a mention, once the app's @MeoCord({ guards }) allow it, and an app's own handler
for the word runs instead. The reply's text comes from the presenter's messageHelp when it has one.
Default: false
See also
- MessageHandler
- Message commands