Discord seems to have troubles editing an interaction, but still doing it

I have troubles handling interactions reply with the single function below: i have a board with buttons, and when using one the bot should reply with another board of the same type. Then, I have to click another button before having a final confirmation message, but at this point the reply content is edited alone, the button stay in the loading position before being edited and I have the interaction failed error, event though the reply was sent and I didn't receive any error (video linked)
if (intera.replied)
await intera.editReply(data).catch(async e => {
console.error(e);
await intera.deleteReply().catch(e => e);
return await intera.followUp(data);
})

else if (intera.deferred)
return await intera.editReply(data);

else
return await intera.reply(data);
if (intera.replied)
await intera.editReply(data).catch(async e => {
console.error(e);
await intera.deleteReply().catch(e => e);
return await intera.followUp(data);
})

else if (intera.deferred)
return await intera.editReply(data);

else
return await intera.reply(data);
The problem happens on editReply, I don't understand why as I am using it the right way (or do I?) IMO editReply should be usable several times, I you may edit multiple times a reply It's only visual as absolutely no error is triggered, but still really annoying as the user would think that something went wrong.
13 Replies
d.js toolkit
d.js toolkit5mo 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
Syjalo
Syjalo5mo ago
You should use .update() on the coming interaction, not .editReply() on the old interaction. If you don't respond to the interaction that just created, Discord won't know if it's successful.
Kyusaor
KyusaorOP5mo ago
Update trigger the already aknowledged interaction error For the case that I show in the video, the first click trigger the basic reply, and then editReply on the second clic What's brainfucking me is that it doesn't actually crash Everything run normally The error is only present in the app
Syjalo
Syjalo5mo ago
Did you use .deferUpdate()?
Kyusaor
KyusaorOP5mo ago
Nope But I tried doing so, and the problem remains It only happens when I use editReply
Syjalo
Syjalo5mo ago
It's hard to say without seeing the actual code of sending editing these buttons
Kyusaor
KyusaorOP5mo ago
The function handling this is the code block in my initial message It's the global function I'm calling for each reply/editReply I use in the code
Syjalo
Syjalo5mo ago
Yeah I saw that code. But I need the code that use this function
Kyusaor
KyusaorOP5mo ago
I tried switching the global function with reply + editreply, and the problem remained I'm not on my pc rn, I'll give the code later if you want
let payload = this.generateTypeEventMessage(button, language); //Returns a message payload
await Command.prototype.reply({ content: payload.message, components: payload.buttons }, button); //The function I wrote in my initial message

let eventData = this.getEventData(event, button.customId);
let confirmation = await Command.getConfirmationMessage(button, "setglobalping", language, { text: this.getConfirmationMessage(language, eventData)/*this returns a message payload object*/, deleteMsg: true });




//Definition of the function I'm calling
static async getConfirmationMessage(intera: ChatInputCommandInteraction | ButtonInteraction, commandname: CommandName, language: textLanguage, options?: { text?: string, embeds?: EmbedBuilder[], time?: number, ephemeral?: boolean, deleteMsg?: boolean }) {
let payload: MessagePayload | InteractionReplyOptions = { content: options?.text, components: [Command.generateYesNoButtons(commandname, language)], ephemeral: options?.ephemeral };
if (options?.embeds)
payload.embeds = options?.embeds
await Command.prototype.reply(payload, intera);

let confirmationResponse;
try {
let filter = (button: ButtonInteraction<"cached">) => button.user.id === intera.user.id && button.customId.includes(commandname)
confirmationResponse = await intera.channel?.awaitMessageComponent({ componentType: ComponentType.Button, filter, time: options?.time || 15000 })
} catch {
intera.channel?.lastMessage?.delete().catch(e => Console.error(e));
return "error"
}
// + some stuff to delete the message and returning a value, not reached for the current problem so I didn't shared
}
let payload = this.generateTypeEventMessage(button, language); //Returns a message payload
await Command.prototype.reply({ content: payload.message, components: payload.buttons }, button); //The function I wrote in my initial message

let eventData = this.getEventData(event, button.customId);
let confirmation = await Command.getConfirmationMessage(button, "setglobalping", language, { text: this.getConfirmationMessage(language, eventData)/*this returns a message payload object*/, deleteMsg: true });




//Definition of the function I'm calling
static async getConfirmationMessage(intera: ChatInputCommandInteraction | ButtonInteraction, commandname: CommandName, language: textLanguage, options?: { text?: string, embeds?: EmbedBuilder[], time?: number, ephemeral?: boolean, deleteMsg?: boolean }) {
let payload: MessagePayload | InteractionReplyOptions = { content: options?.text, components: [Command.generateYesNoButtons(commandname, language)], ephemeral: options?.ephemeral };
if (options?.embeds)
payload.embeds = options?.embeds
await Command.prototype.reply(payload, intera);

let confirmationResponse;
try {
let filter = (button: ButtonInteraction<"cached">) => button.user.id === intera.user.id && button.customId.includes(commandname)
confirmationResponse = await intera.channel?.awaitMessageComponent({ componentType: ComponentType.Button, filter, time: options?.time || 15000 })
} catch {
intera.channel?.lastMessage?.delete().catch(e => Console.error(e));
return "error"
}
// + some stuff to delete the message and returning a value, not reached for the current problem so I didn't shared
}
Feel free to ask any clarification, I tried to make it as readable as possible Ah, you got a point, I'll try that It doesn't work: the interaction is already sent, so calling update would trigger the already sent error. And I can't call it in the first place, because the board is meant to be static so it would edit the board message to use update first Event tho using update after all this is still a better thing to do, my problem is located before that The first click trigger a interaction.reply, resulting in the list message with the numbers. Then, I click and it triggers an editReply, editing the message. But the problem is that even though the interaction is actually edited right away, the buttons stay in the loading position and give the interaction failed error after the 3s delay As if Discord isn't aware that it successfully edited the interaction, if I should schematize the problem It doesn't work Update is used for the initial response And i don't want to update the initial message, as it is the board I must reply first if I wanna keep the board in place Calling update on that message triggers the already aknowledged interaction error, I already tried It's considered as a reply to the first interaction I actually called it on the interaction, I just poor-worded my sentence, my bad If you want to see the global interaction event handler, i didn't showed it as it's not triggered by my current case (only the initial interaction, that seems to work as intended), and I don't want to flood you with irrelevant code
d.js docs
d.js docs5mo ago
To share long code snippets, use a service like gist, sourcebin, pastebin, or similar instead of posting them as large code blocks or files.
Kyusaor
KyusaorOP5mo ago
Hum, would it be easier to understand if I point to you the starting point in the github repo, and you follow it by yourself from there ?
Kyusaor
KyusaorOP5mo ago
GitHub
Sparky/src/main.ts at main · Kyusaor/Sparky
Bot d'aide pour Lords Mobile. Contribute to Kyusaor/Sparky development by creating an account on GitHub.
Kyusaor
KyusaorOP5mo ago
The command is called setglobalping in the buttonInteraction handler Ah, it's probably that indeed I'll try tomorrow, I'll let you know if it's working. Thanks for taking your time to help! Yup, obviously I already started to fix that earlier It worked, thanks
Want results from more Discord servers?
Add your server