#Disabling button once user clicked on it

1 messages ยท Page 1 of 1 (latest)

main heart
#

This is my full code right now:

const express = require("express");
const {
  Discord,
  Client,
  Intents,
  MessageEmbed,
  MessageButton,
  MessageActionRow,
} = require("discord.js");

const router = express.Router();

// Setup Discord client to listen to events
const client = new Client({
  intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
});

// Logs the bot into Discord
client.login(process.env.DISCORD_TOKEN);

// Notifies whether the bot is live
client.on("ready", () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

const startButton = new MessageButton()
  .setCustomId("Start")
  .setLabel("Run ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป")
  .setStyle("PRIMARY");

const runButton = new MessageButton()
  .setCustomId("Run")
  .setLabel("Run ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป")
  .setStyle("PRIMARY");

const fleeButton = new MessageButton()
  .setCustomId("Flee")
  .setLabel("Flee ๐Ÿƒ๐Ÿป")
  .setStyle("DANGER");

// Kicks-off run bot
client.on("interactionCreate", async (interaction) => {
  if (interaction.commandName === "run") {
    const row = new MessageActionRow().addComponents(startButton);
    const embed = new MessageEmbed()
      .setColor("#0099ff")
      .setImage(
        "https://cdn.pastemagazine.com/www/articles/android_digital_edition_main.jpg"
      )
      .setTitle("Run Start!")
      .setDescription(
        "You strap into your console and feel the rush in your veins while you jack into the Grid..."
      );

    await interaction.reply({
      ephemeral: true,
      embeds: [embed],
      components: [row],
    });
  }
});

// Handles user interactions
client.on("interactionCreate", async (interaction) => {
  if (interaction.customId === "Start") {
    const row = new MessageActionRow().addComponents(runButton, fleeButton);

    const embed = new MessageEmbed()
      .setColor("#0099ff")
      .setImage("https://i.stack.imgur.com/rQm5c.png")
      .setTitle("Adonis ICE shows up!")
      .setDescription(
        "A sphix presents itself and watches your every movement. What do you do now?"
      );

    let botReply = await interaction.reply({
      ephemeral: true,
      embeds: [embed],
      components: [row],
    });
  } else if (interaction.customId === "Run") {
    const embed = new MessageEmbed()
      .setColor("#0099ff")
      .setImage(
        "https://media.wired.com/photos/6018a8463453f789506008b8/16:9/w_1471,h_827,c_limit/games_netrunner.jpg"
      )
      .setTitle("You hit the ICE with a ICEbreaker_3xC4l1bUR program!")
      .setDescription(
        "The sphinx ICE had no chance against your program and it was destroyed!"
      );

    let botReply = await interaction.reply({
      ephemeral: true,
      embeds: [embed],
    });
  } else if (interaction.customId === "Flee") {
    const embed = new MessageEmbed()
      .setColor("#0099ff")
      .setImage(
        "https://www.ultraboardgames.com/android-netrunner/gfx/netrunner5.jpg"
      )
      .setTitle("You made it safely out of the Grid")
      .setDescription(
        "You live to fight the Corps another day, chum. Enjoy ya day."
      );

    let botReply = await interaction.reply({
      ephemeral: true,
      embeds: [embed],
    });
  }

  const filter = (i) => i.customId === "Start";

  const collector = interaction.channel.createMessageComponentCollector({
    filter,
    time: 1000,
  });

  collector.on("collect", async (i) => {
    if (i.customId === "Start") {
      console.log("test3");
      await i.editReply({ components: [] });
    }
  });

  collector.on("end", (collected) => {
    console.log("test2");
    console.log(`Collected ${collected.size} items`);
  });
});

module.exports = router;
#

I'm trying to collect the reply event (button click) so I can edit the original message and disable the buttons

queen ridge
#

In collector you collect a new interaction i is a new interaction that has nothing to do with interaction

#

so you need to reply to it

main heart