From e5bf5cd47cdfc61fd29c95899fae866d22f48144 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Sat, 6 Mar 2021 13:59:45 -0500 Subject: [PATCH] feat(handlers/webhook): support ephemeral messages (#602) Co-authored-by: ayntee --- src/api/handlers/webhook.ts | 9 +++++++-- src/types/webhook.ts | 8 +++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/api/handlers/webhook.ts b/src/api/handlers/webhook.ts index fdad0ec4b..74fda402b 100644 --- a/src/api/handlers/webhook.ts +++ b/src/api/handlers/webhook.ts @@ -6,10 +6,10 @@ import { EditSlashResponseOptions, EditWebhookMessageOptions, Errors, - ExecuteSlashCommandOptions, ExecuteWebhookOptions, MessageCreateOptions, SlashCommand, + SlashCommandResponseOptions, UpsertSlashCommandOptions, UpsertSlashCommandsOptions, WebhookCreateOptions, @@ -448,7 +448,7 @@ export function deleteSlashCommand(id: string, guildID?: string) { export async function executeSlashCommand( id: string, token: string, - options: ExecuteSlashCommandOptions, + options: SlashCommandResponseOptions, ) { // If its already been executed, we need to send a followup response if (cache.executedSlashCommands.has(token)) { @@ -464,6 +464,11 @@ export async function executeSlashCommand( 900000, ); + // If the user wants this as a private message mark it ephemeral + if (options.private) { + options.data.flags = 64; + } + // If no mentions are provided, force disable mentions if (!(options.data.allowed_mentions)) { options.data.allowed_mentions = { parse: [] }; diff --git a/src/types/webhook.ts b/src/types/webhook.ts index d5a680785..225034a86 100644 --- a/src/types/webhook.ts +++ b/src/types/webhook.ts @@ -191,7 +191,7 @@ export interface SlashCommandCallbackData { embeds?: Embed[]; /** allowed mentions for the message */ "allowed_mentions"?: AllowedMentions; - /** acceptable values are message flags */ + /** acceptable values are message flags, set to 64 to make your response ephemeral */ flags?: number; } @@ -224,6 +224,12 @@ export interface ExecuteSlashCommandOptions { data: SlashCommandCallbackData; } +export interface SlashCommandResponseOptions + extends ExecuteSlashCommandOptions { + /** Whether to make this response visible ONLY to the user who used this command. It will also be deleted after some time. */ + private?: boolean; +} + export interface EditSlashResponseOptions extends SlashCommandCallbackData { /** If this is not provided, it will default to editing the original response. */ messageID?: string;