From d6c4868ccf46c5217954c2b55ef0c9e1fec0c1d9 Mon Sep 17 00:00:00 2001 From: Dragory <2606411+Dragory@users.noreply.github.com> Date: Wed, 18 Aug 2021 21:01:57 +0300 Subject: [PATCH] Make sure waitForButtonConfirm() component custom IDs are unique --- backend/src/utils/waitForInteraction.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/backend/src/utils/waitForInteraction.ts b/backend/src/utils/waitForInteraction.ts index afc3641f..e7e4ae7d 100644 --- a/backend/src/utils/waitForInteraction.ts +++ b/backend/src/utils/waitForInteraction.ts @@ -1,6 +1,7 @@ import { MessageActionRow, MessageButton, MessageComponentInteraction, MessageOptions, TextChannel } from "discord.js"; import { noop } from "knub/dist/utils"; import moment from "moment"; +import uuidv4 from "uuid/v4"; export async function waitForButtonConfirm( channel: TextChannel, @@ -13,12 +14,12 @@ export async function waitForButtonConfirm( new MessageButton() .setStyle("SUCCESS") .setLabel(options?.confirmText || "Confirm") - .setCustomId(`confirmButton:${idMod}`), + .setCustomId(`confirmButton:${idMod}:${uuidv4()}`), new MessageButton() .setStyle("DANGER") .setLabel(options?.cancelText || "Cancel") - .setCustomId(`cancelButton:${idMod}`), + .setCustomId(`cancelButton:${idMod}:${uuidv4()}`), ]); const message = await channel.send({ ...toPost, components: [row] }); @@ -28,10 +29,10 @@ export async function waitForButtonConfirm( if (options?.restrictToId && options.restrictToId !== interaction.user.id) { interaction.reply({ content: `You are not permitted to use these buttons.`, ephemeral: true }); } else { - if (interaction.customId === `confirmButton:${idMod}`) { + if (interaction.customId.startsWith(`confirmButton:${idMod}:`)) { message.delete(); resolve(true); - } else if (interaction.customId === `cancelButton:${idMod}`) { + } else if (interaction.customId.startsWith(`cancelButton:${idMod}:`)) { message.delete(); resolve(false); }