Skip to content

Commit 5b0fa37

Browse files
fix: allow embeds to be removed if all fields are undefined
1 parent 054b563 commit 5b0fa37

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

src/interactions/buttons/message-generation.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,22 @@ const handleSend = async ({
346346
url: messageLink,
347347
timestamp: new Date().toISOString(),
348348
};
349+
// Check embed for any set values. If none set embed to undefined
350+
if (currentStatus.embed !== undefined) {
351+
const hasAnySet =
352+
(currentStatus.embed?.fields?.length ?? 0) > 0 ||
353+
currentStatus.embed?.author?.name !== undefined ||
354+
currentStatus.embed?.footer?.text !== undefined ||
355+
currentStatus.embed?.description !== undefined ||
356+
currentStatus.embed?.title !== undefined ||
357+
currentStatus.embed?.url !== undefined ||
358+
currentStatus.embed?.thumbnail?.url !== undefined ||
359+
currentStatus.embed?.timestamp !== undefined ||
360+
currentStatus.embed?.color !== undefined;
361+
if (!hasAnySet) {
362+
currentStatus.embed = undefined;
363+
}
364+
}
349365

350366
return {
351367
type: InteractionResponseType.UpdateMessage,
@@ -382,6 +398,23 @@ const handleEdit = async ({
382398
);
383399
}
384400

401+
// Check embed for any set values. If none set embed to undefined
402+
if (currentStatus.embed !== undefined) {
403+
const hasAnySet =
404+
(currentStatus.embed?.fields?.length ?? 0) > 0 ||
405+
currentStatus.embed?.author?.name !== undefined ||
406+
currentStatus.embed?.footer?.text !== undefined ||
407+
currentStatus.embed?.description !== undefined ||
408+
currentStatus.embed?.title !== undefined ||
409+
currentStatus.embed?.url !== undefined ||
410+
currentStatus.embed?.thumbnail?.url !== undefined ||
411+
currentStatus.embed?.timestamp !== undefined ||
412+
currentStatus.embed?.color !== undefined;
413+
if (!hasAnySet) {
414+
currentStatus.embed = undefined;
415+
}
416+
}
417+
385418
await editMessage({
386419
channelId,
387420
messageId: currentStatus.messageId,

src/interactions/shared/message-generation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ const createInitialMessageGenerationEmbed = (
5959
}`,
6060
description:
6161
`Use the buttons below to update the state of the message and embed. When you are done, click the ${type} button.` +
62+
`\nTo remove the embed, if you have not already done so, make sure all fields and other properties are removed (empty)` +
6263
"\n\n" +
6364
`${
6465
currentStatus.content !== undefined
@@ -175,7 +176,8 @@ const createEmbedMessageGenerationEmbed = (
175176
embed: addTipToEmbed({
176177
title: "Message Generation Flow - Embed",
177178
description:
178-
"Use the buttons below to update the state of the embed. When you are done, click the back button.",
179+
"Use the buttons below to update the state of the embed. When you are done, click the back button." +
180+
"\nTo remove the embed, if you have not already done so, make sure all fields and other properties are removed (empty)",
179181
color: embedPink,
180182
}),
181183
components: [

0 commit comments

Comments
 (0)