Skip to content

Commit

Permalink
feat: allow posting interaction callbacks for webservers
Browse files Browse the repository at this point in the history
  • Loading branch information
Snazzah committed Sep 10, 2024
1 parent 2459a91 commit 6692147
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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. */
Expand Down

0 comments on commit 6692147

Please sign in to comment.