Skip to content
GitHub

Defer

function in meocord/decorator Since 4.1.0

Defer(options?: DeferOptions): MethodDecorator

Acknowledges an interaction for its handler, then locks a component's message while the handler runs.

Use it on a handler that may take longer than Discord's three seconds, such as one that queries a database or an API. For a handler that shows a modal, which must be the first answer, leave it out.

Where it runs

Parameters

NameTypeDefaultDescription
options?DeferOptions

Whether the reply is private, what to disable, and whether to acknowledge at once.

options.ephemeral?booleanfalse

Makes a command's deferred reply private.

options.suppressNotifications?booleanfalse

Sends new messages without notifying: the first reply, when there was time to answer before deferring, and follow-ups.

options.disable?'all' | 'clicked' | 'none''all'

Which controls of a component's message to disable while the handler runs: every one, the one clicked, or none, which also leaves out the loading view.

options.mode?'eager' | 'auto''eager'

When to acknowledge: 'eager' at once, or 'auto' only if nothing answered after after milliseconds, so a fast handler answers with a single reply. 'auto' suits a handler that waits on I/O: a timer cannot fire while synchronous work blocks the event loop.

options.after?number1500

How long 'auto' waits before acknowledging, in milliseconds. It never waits past 2.5 seconds after the interaction was created.

Returns

Returns a method decorator.

MethodDecorator

Throws

  • Error on a message, reaction, event or autocomplete handler: as the decorator applies when it is written above the handler's decorator, and as the app is created otherwise.

Examples

TypeScript
constructor(private readonly profiles: ProfileService) {}

@Command('refresh/{uid}', CommandType.BUTTON)
@Defer()
async refresh(interaction: ButtonInteraction, { uid }: { uid: string }) {
  await respond(interaction).send({ embeds: [await this.profiles.render(uid)] })
}