MessageParamType
interface in meocord/interface Since 4.1.0
interface MessageParamType<T = unknown>A param type an app adds for its message patterns, such as {accent:color}: it reads a word as a value.
Add one for a value the built-in types do not cover, such as a colour, an item from your catalogue or an
order ID. Register it in @MeoCord({ messages: { types } }) by the name patterns use, and declare what it
gives in MessageParamTypes, so handlers using it are typed.
Examples
const color: MessageParamType<number> = {
label: 'hex colour',
parse: word => (/^#[0-9a-f]{6}$/i.test(word) ? parseInt(word.slice(1), 16) : undefined),
}
// @MeoCord({ messages: { types: { color } } }), and in a .d.ts of the app, which imports it to extend it:
import 'meocord/interface'
declare module 'meocord/interface' {
interface MessageParamTypes { color: number }
}Members
label
label?: stringA noun such as hex colour, read in "is not a valid hex colour". Defaults to the type's key.
labelKey
labelKey?: stringA message key of the app's catalog, such as types.color, whose text is the label in each reply's language.
It needs @MeoCord({ i18n }), and the default catalog must have the message.
parse
parse(
word: string,
message: Message,
): T | EntityRef<T> | undefined | Promise<T | EntityRef<T> | undefined>The value a word stands for, or undefined when it stands for none. It runs before the handler's guards,
so a caller they refuse can reach it: it should not call Discord. For something that needs a request,
return an EntityRef, whose resolve() runs only once the guards let the call through; guards see
the ref, and the handler the value it resolves to.
Parameters
| Name | Type | Description |
|---|---|---|
word | string | |
message | Message |
Returns
T | EntityRef<T> | undefined | Promise<T | EntityRef<T> | undefined>See also
- Message params