Defer
function in meocord/decorator Since 4.1.0
Defer(options?: DeferOptions): MethodDecoratorAcknowledges 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
| Name | Type | Default | Description |
|---|---|---|---|
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. |
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: |
options.after? | number | 1500 | How long |
Returns
Returns a method decorator.
MethodDecoratorThrows
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
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)] })
}