Route
interface in meocord/common Since 4.1.0
interface Route<T extends string = string>A component's customId pattern with a typed build and match, as route makes it.
Pass it to @Command in place of the pattern's text, build the customIds that reach its handler, and match
one to read its params back.
Members
pattern
readonly pattern: TThe pattern, as written.
build
build(
...values: [RouteParams<T>] extends [never] ? [] : [values: RouteValues<T>]
): stringA customId this route matches, with each param's value in its segment. / and % in a value are
encoded, and the handler receives the value as it was given.
Parameters
| Name | Type |
|---|---|
...values | [RouteParams<T>] extends [never]
? []
: [values: RouteValues<T>] |
Returns
stringThrows
TypeError for a missing, empty or unknown value or one not of its param's type, and RangeError for an id that is empty or over 100 characters.
match Since 4.3.0
match(customId: string): RouteMatch<T> | undefinedReads a customId's params as this route's handler receives them, for a customId the bot did not get as a
handler call, such as another button on the message. / and % that build encoded come back as they were
given, and a typed param comes back as its value.
Parameters
| Name | Type |
|---|---|
customId | string |
The customId to read. | |
Returns
RouteMatch<T> | undefinedThe params, an empty object for a pattern without params, or undefined when the customId doesn't match
the pattern or a segment isn't a value of its param's type.
Examples
const closeTicket = route('ticket/{id:int}/close')
closeTicket.match('ticket/42/close') // { id: 42 }
closeTicket.match('ticket/new/close') // undefined: 'new' isn't an int
closeTicket.match('poll/1') // undefinedtoString
toString(): TThe pattern, so a route reads as its pattern in a template string.
Returns
T