Editing interaction message gives an error

I am making a queue system for my discord bot and I have a command where you do it sends a message and a join queue button attached to the message. If you click that button it edits the original message and adds: "Queue: member.user.tag" Then it also sends you an ephemeral message letting you know that you joined, attached to that ephemeral message is a Leave Queue button that if you click it is supposed to edit the original "Queue: member.user.tag" and remove member.user.tag from it. But it errors when I do interaction.message.edit({content: queueMessage,}); in leaveQueue.
client.on("interactionCreate", async (interaction) => {
if (!interaction.isButton()) return;

await interaction.deferUpdate();

const member = interaction.member;
if (interaction.customId === "joinQueue") {

if (!queue.includes(member)) {

queue.push(member);


const queueMessage = `**Queue:**\n${queue
.map((m) => m.user.tag)
.join("\n")}`;

interaction.message.edit({
content: queueMessage,
});
const leaveQueueButton = new ButtonBuilder()
.setCustomId("leaveQueue")
.setLabel("Leave Queue")
.setStyle(ButtonStyle.Danger);

const row = new ActionRowBuilder().addComponents(leaveQueueButton);
interaction.followUp({
content: "You joined the queue!",
components: [row],
ephemeral: true,
});
console.log(`${member.user.tag} has joined the queue.`);
}
} else if (interaction.customId === "leaveQueue") {

const index = queue.indexOf(member);
console.log(index);
if (index !== -1) {
queue.splice(index, 1);


const queueMessage = `**Queue:**\n${queue.join("\n")}`;

interaction.message.edit({
content: queueMessage,
});
interaction.followUp({
content: "You left the queue!",
ephemeral: true,
});
console.log(`${member.user.tag} has left the queue.`);
}
}
});
client.on("interactionCreate", async (interaction) => {
if (!interaction.isButton()) return;

await interaction.deferUpdate();

const member = interaction.member;
if (interaction.customId === "joinQueue") {

if (!queue.includes(member)) {

queue.push(member);


const queueMessage = `**Queue:**\n${queue
.map((m) => m.user.tag)
.join("\n")}`;

interaction.message.edit({
content: queueMessage,
});
const leaveQueueButton = new ButtonBuilder()
.setCustomId("leaveQueue")
.setLabel("Leave Queue")
.setStyle(ButtonStyle.Danger);

const row = new ActionRowBuilder().addComponents(leaveQueueButton);
interaction.followUp({
content: "You joined the queue!",
components: [row],
ephemeral: true,
});
console.log(`${member.user.tag} has joined the queue.`);
}
} else if (interaction.customId === "leaveQueue") {

const index = queue.indexOf(member);
console.log(index);
if (index !== -1) {
queue.splice(index, 1);


const queueMessage = `**Queue:**\n${queue.join("\n")}`;

interaction.message.edit({
content: queueMessage,
});
interaction.followUp({
content: "You left the queue!",
ephemeral: true,
});
console.log(`${member.user.tag} has left the queue.`);
}
}
});
No description
8 Replies
d.js toolkit
d.js toolkit8mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Flight
Flight8mo ago
Versions:
$ node -v
v21.1.0
$ node -v
v21.1.0
$ npm list discord.js
ff-trivia@1.0.0 ...\ff-trivia
└── discord.js@14.13.0
$ npm list discord.js
ff-trivia@1.0.0 ...\ff-trivia
└── discord.js@14.13.0
treble/luna
treble/luna8mo ago
You have to call editReply on the original interaction ephemeral messagez cannot be edited like that
Flight
Flight8mo ago
How would I get the original interaction? I am not trying to edit the ephemeral message, I'm trying to edit the original message.
treble/luna
treble/luna8mo ago
You can use interaction.update
Flight
Flight8mo ago
I did:
let initialMessage;
let initialMessage;
initialMessage = interaction;
initialMessage = interaction;
initialMessage.editReply({
content: queueMessage,
});
initialMessage.editReply({
content: queueMessage,
});
Is this solution fine?
treble/luna
treble/luna8mo ago
did you reply to the interaction before?
Flight
Flight8mo ago
Yea I replied when they clicked the join queue button:
client.on("interactionCreate", (interaction) => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === "startgame") {
if (roundInProgress) {
interaction.reply({
embeds: [
{
title: "Game in progress",
description: "Please wait for the current game to finish.",
color: 0xff0000, // Red color
},
],
ephemeral: true,
});
} else {
initialMessage = interaction;
const joinQueueButton = new ButtonBuilder()
.setCustomId("joinQueue")
.setLabel("Join Queue")
.setStyle(ButtonStyle.Primary);

const row = new ActionRowBuilder().addComponents(joinQueueButton);

const initialQueueMessage = "Waiting for players to join the queue...";

interaction.reply({
content: initialQueueMessage,
components: [row],
});

roundInProgress = true;
}
}
});
client.on("interactionCreate", (interaction) => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === "startgame") {
if (roundInProgress) {
interaction.reply({
embeds: [
{
title: "Game in progress",
description: "Please wait for the current game to finish.",
color: 0xff0000, // Red color
},
],
ephemeral: true,
});
} else {
initialMessage = interaction;
const joinQueueButton = new ButtonBuilder()
.setCustomId("joinQueue")
.setLabel("Join Queue")
.setStyle(ButtonStyle.Primary);

const row = new ActionRowBuilder().addComponents(joinQueueButton);

const initialQueueMessage = "Waiting for players to join the queue...";

interaction.reply({
content: initialQueueMessage,
components: [row],
});

roundInProgress = true;
}
}
});