code fragment sent by Kevin Kumar#4660
export default async function (
interaction: CommandInteraction | ButtonInteraction | SelectMenuInteraction | Message,
frage: InteractionReplyOptions,
onConfirm?: (i: ButtonInteraction) => void,
customJa?: string
) {
const uniqueId = nanoid();
if (!interaction) return console.log("error" + "🚀 No interaction found in confirm");
const ja = new MessageButton()
.setCustomId(uniqueId)
.setLabel(customJa ?? "Ja")
.setStyle("SUCCESS");
if (interaction instanceof Message) {
interaction.reply({
...frage,
components: [new MessageActionRow().addComponents([ja])],
});
} else {
interaction.reply({
content: `<@${interaction.user.id}>\n ${frage.content}`,
components: [new MessageActionRow().addComponents([ja])],
ephemeral: true,
...frage,
});
}
const collector = interaction.channel.createMessageComponentCollector({
componentType: "BUTTON",
time: COLLECTOR_TIME,
});
collector.on("collect", async (i: ButtonInteraction) => {
if (i.customId == uniqueId) {
await onConfirm(i);
}
});
collector.on("dispose", (i) => {
if (collector.collected.size === 0) {
i.reply({
content: COLLECTORDISPOSEMESSAGE,
ephemeral: true,
});
}
});
}
code fragment sent by Kevin Kumar#4660