ResponsePresenter
interface in meocord/interface Since 4.1.0
interface ResponsePresenterStyles MeoCord's own answers: the loading view @Defer shows, the error view respond().error() shows, and, with
messageError, the error replies and direct messages the built-in fallback sends a message command's author.
Implement it to give those views your bot's look, and register it with @MeoCord({ presenter }). It decides how
they look, not what they say: filters and the built-in fallback choose the words. A view may carry files, such as
an image drawn with a canvas library, which MeoCord attaches and shows, and each method may draw asynchronously.
Examples
@Service()
export class BrandPresenter implements ResponsePresenter {
loading({ theme }: ResponseContext) {
return { text: 'Working on it…', emoji: theme.emojis.loading, color: theme.colors.primary }
}
error({ theme }: ResponseContext, { message, tone }: PresentedError) {
return { title: 'Something went wrong', text: message, color: theme.colors[tone] }
}
}An error drawn as an image, which MeoCord attaches and shows as the embed's image:
@Service()
export class CardPresenter implements ResponsePresenter {
constructor(private readonly cards: CardRenderer) {}
loading() {
return { text: 'Working on it…' }
}
async error(_context: ResponseContext, { message }: PresentedError) {
return { text: message, files: [{ name: 'error.png', data: await this.cards.draw('Oops!', message) }] }
}
}Members
loading
loading(context: ResponseContext): ResponseView | Promise<ResponseView>The view shown while a handler under @Defer works. It may draw it asynchronously: MeoCord acknowledges the
interaction first, so a slow drawing never misses Discord's three seconds. The handler waits for it, so a drawing
that takes longer than a second is given up on, with a warning, and MeoCord's own loading view is shown.
Parameters
| Name | Type | Description |
|---|---|---|
context | ResponseContext |
Returns
ResponseView | Promise<ResponseView>error
error(
context: ResponseContext,
error: PresentedError,
): ResponseView | Promise<ResponseView>The view shown for an error. It may draw it asynchronously: an interaction not yet acknowledged is acknowledged first, privately, and the view then replaces the acknowledgement. Discord refusing that acknowledgement, such as for an interaction past its three seconds, is logged as the send it is, never as the presenter failing.
Parameters
| Name | Type | Description |
|---|---|---|
context | ResponseContext | |
error | PresentedError |
Returns
ResponseView | Promise<ResponseView>messageError
messageError?(
context: MessageResponseContext,
error: PresentedError,
): ResponseView | Promise<ResponseView>The view a message command's error reply is drawn as: its usage, a guard's or validation's reason, a UserError's
message, and the direct messages dmOnError and dmOnCooldown send. Without this method they are plain text. The
view is sent as an embed, with its files. Should it throw or reject, or return a view MeoCord cannot render, the
reply is sent as plain text, and the failure is then reported as the call's fault, as for error.
Parameters
| Name | Type | Description |
|---|---|---|
context | MessageResponseContext | The message being answered, its locale and theme. |
error | PresentedError | The words the fallback chose, the error, and its tone. |
Returns
ResponseView | Promise<ResponseView>messageHelp
messageHelp?(
help: MessageHelp,
message: Message,
): string | MessageReplyOptions | Promise<string | MessageReplyOptions>The reply to the built-in help message command, from what it found; without this method MeoCord writes it in
plain text. Return text, or the options message.reply takes, such as an embed.
Parameters
| Name | Type | Description |
|---|---|---|
help | MessageHelp | What the caller asked about and what they can use, as |
message | Message | The message that asked for help. |
Returns
string | MessageReplyOptions | Promise<string | MessageReplyOptions>