From 669214762cd37775daf7ed83d5a3bb351b6307d2 Mon Sep 17 00:00:00 2001 From: Snazzah Date: Tue, 10 Sep 2024 18:33:54 -0500 Subject: [PATCH] feat: allow posting interaction callbacks for webservers --- src/creator.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/creator.ts b/src/creator.ts index 504d314e..97df39fd 100644 --- a/src/creator.ts +++ b/src/creator.ts @@ -74,6 +74,7 @@ export class BaseSlashCreator extends (EventEmitter as any as new () => TypedEve handleCommandsManually: false, disableTimeouts: false, componentTimeouts: false, + postCallbacks: false, latencyThreshold: 30000, ratelimiterOffset: 0, requestTimeout: 15000, @@ -562,7 +563,14 @@ export class BaseSlashCreator extends (EventEmitter as any as new () => TypedEve ) { this.emit('rawInteraction', interaction); - if (!respond || !webserverMode) respond = this._createGatewayRespond(interaction.id, interaction.token); + // User preferred POSTing callbacks + if (this.options.postCallbacks && respond) + await respond({ + status: 202 + }); + + if (!respond || !webserverMode || this.options.postCallbacks) + respond = this._createGatewayRespond(interaction.id, interaction.token); switch (interaction.type) { case InteractionType.PING: { @@ -841,6 +849,11 @@ export interface SlashCreatorOptions { disableTimeouts?: boolean; /** Whether to enable automatic component timeouts. */ componentTimeouts?: boolean; + /** + * Whether to POST callbacks rather than responding via the webserver. + * Webservers will serve an immediate 202 to Discord, and will POST an interaction callback later. + */ + postCallbacks?: boolean; /** The default allowed mentions for all messages. */ allowedMentions?: MessageAllowedMentions; /** The default format to provide user avatars in. */