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

  • @Defer: acknowledge — before the guards, acknowledging the interaction
  • @Defer: lock — after the cooldowns count the call, just before the handler

Parameters

NameTypeDefault
options?DeferOptions

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

options.ephemeral?boolean

false

Makes a command's deferred reply private. Under mode: 'auto', an acknowledgement sent while an answer waits for its theme stands in for that answer's own reply, and is as private as that answer instead.

options.suppressNotifications?boolean

false

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 no answer has been sent to Discord after after milliseconds, so a fast handler answers with a single reply. An answer still waiting for its theme, as from a slow themeFor resolver, doesn't count: the acknowledgement goes first, as private as that answer, which then edits it in. 'auto' suits a handler that waits on I/O: a timer cannot fire while synchronous work blocks the event loop.

options.after?number

1500

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)] })
}