Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Component Collection (Kevin Kumar) #195

Open
mchangrh opened this issue Sep 15, 2021 · 0 comments
Open

Component Collection (Kevin Kumar) #195

mchangrh opened this issue Sep 15, 2021 · 0 comments

Comments

@mchangrh
Copy link
Member

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,
      });
    }
  });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant