I'm trying to make the bot disable the button after it's used, but it isn't working, because it is saying that b.setDisabled is not a function. How can I solve this?
const {
SlashCommandBuilder,
EmbedBuilder,
ButtonStyle,
ButtonBuilder,
ActionRowBuilder,
ActionRow,
} = require("discord.js");
module.exports = {
data: new SlashCommandBuilder()
.setName("highlow")
.setDescription(" | Starts a new high or low game!"),
async execute(interaction) {
const randomNumber = Math.floor(Math.random() * 100) + 1;
const hintNumber = Math.floor(Math.random() * 100) + 1;
const row = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setLabel("High")
.setStyle(ButtonStyle.Secondary)
.setCustomId("high"),
new ButtonBuilder()
.setCustomId("low")
.setLabel("Low")
.setStyle(ButtonStyle.Secondary),
new ButtonBuilder()
.setCustomId("correct")
.setLabel("Same")
.setStyle(ButtonStyle.Secondary)
);
const sent = await interaction.reply({
content: `Is my number higher or lower than ${hintNumber}?`,
components: [row],
});
const collector = sent.createMessageComponentCollector({
filter: (i) =>
i.user.id === interaction.user.id && i.message.id === sent.id,
time: 30000,
max: 1,
});
let won = false;
collector.on("collect", async (i) => {
await i.deferUpdate({ fetchReply: true });
row.forEach((b) => b.setDisabled(true));
if (i.customId === "high") {
if (hintNumber > randomNumber) {
row.forEach((b) => {
if (b.customId === "high") b.setStyle(ButtonStyle.Danger);
});
await interaction.editReply({
content: `Sadge, you got it wrong! It was ${randomNumber}`,
components: [row],
});
won = false;
} else {
row.forEach((b) => {
if (b.customId === "high") b.setStyle(ButtonStyle.Success);
});
await interaction.editReply({
content: `You guessed the number! It was ${randomNumber}`,
components: [row],
});
won = true;
}
} else if (i.customId === "low") {
if (hintNumber < randomNumber) {
row.forEach((b) => {
if (b.customId === "low") b.setStyle(ButtonStyle.Danger);
});
await interaction.editReply({
content: `Sadge, you got it wrong! It was ${randomNumber}`,
components: [row],
});
won = false;
} else {
row.forEach((b) => {
if (b.customId === "low") b.setStyle(ButtonStyle.Success);
});
await interaction.editReply({
content: `You are right! It was ${randomNumber}`,
components: [row],
});
won = true;
}
} else if (i.customId === "correct" && hintNumber === randomNumber) {
row.forEach((b) => {
if (b.customId === "correct") b.setStyle(ButtonStyle.Success);
});
await interaction.editReply({
content: `You guessed the number! It was ${randomNumber}`,
components: [row],
});
won = true;
} else {
await interaction.editReply({
content: `Sadge, you got it wrong! It was ${randomNumber}`,
components: [row],
});
won = false;
}
});
collector.on("end", async (collected) => {
if (!won && collected.size === 0) {
[row].forEach((b) => b.setDisabled(true));
await interaction.editReply({
content: `You didn't guess the number! It was ${randomNumber}`,
components: [row],
});
}
});
},
};