Issues with awaitMessageComponent

hey everyone.. trying to make a little game and having trouble with buttons. if my user sends a slash command, i get an Interaction object, which i can reply to using .reply(), attach buttons to that reply, and get the button output using .awaitMessageComponent(). this works perfectly. .awaitMessageComponent() returns a promise interaction that itself can be replied to. I.E. something like this would hypothetically be able to be done (this is pseudocode - please excuse if there are any minor errors).
async function code(interaction) {
let reply = await interaction.reply({content: "You have encountetered the evil slime. Act:", components: [genComponents()], ephemeral: false };

while (true) {
let confirmation = await reply.awaitMessageComponent({ filter: () => true, time: 180_000 });

await interaction.followUp({content: "Combat messages go here."});

if (playerHealth <= 0) return;

reply = await confirmation.reply({ content: "Act:", components: [genComponents()], ephemeral: false });
}
}
async function code(interaction) {
let reply = await interaction.reply({content: "You have encountetered the evil slime. Act:", components: [genComponents()], ephemeral: false };

while (true) {
let confirmation = await reply.awaitMessageComponent({ filter: () => true, time: 180_000 });

await interaction.followUp({content: "Combat messages go here."});

if (playerHealth <= 0) return;

reply = await confirmation.reply({ content: "Act:", components: [genComponents()], ephemeral: false });
}
}
The idea is that we can reply to the initial slash command with a button message, then once they interact with the buttons, we reply to that interaction, allowing for a pretty clean turn-based combat system. The issue i'm having is, whenever i create a reply to a button interaction, the buttons that i attach to it are unable to be read. I am sure it reaches the await reply.awaitMessageComponent(...) code, but the await simply never finishes and it times out after three minutes, despite me pressing the buttons. I would appreciate any advice on how to fix this error, or perhaps a more idiomatic manner in which i might solve the actual issue i'm having. I am on version 14.16.3. Thank you so much for the help =)
12 Replies
d.js toolkit
d.js toolkit2mo 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
FluxFlu
FluxFluOP2mo ago
discord.js version 14.16.3 node version 22.12.0
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
FluxFlu
FluxFluOP2mo ago
ahh that works but it breaks on ephemeral messages i had specifically done it this way to try and avoid the "10008: Unknown Message" error do you think there is a way to make that happen after all
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Amgelo
Amgelo2mo ago
turning on fetchReply is actually known to fix problems with ephemeral messages can you show your exact code?
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
FluxFlu
FluxFluOP2mo ago
strangely adding fetchReply to the initial reply actually breaks that one too i can send my code shoulds be most of what's relevant
Amgelo
Amgelo2mo ago
you're trying to reply twice? ah nvm thought show was called after pickAbility which components aren't working though? and when?
FluxFlu
FluxFluOP2mo ago
when i make the reply here have fetchReply: true then the code this.response.edit({ components: [] }); in PlayerFighter.pickAbility() throws the error DiscordAPIError[10008]: Unknown Message if i don't make that one fetchReply: true and only have this one in PlayerFighter.show() be fetchReply: true, then the same error is thrown at the same line of code, except that the first one works perfectly fine without needing fetchReply: true, so it only errors once the second button input is performed if i don't use fetchReply: true at all, then the second button input (post PlayerFighter.show()) simply hangs, and the code await this.response.awaitMessageComponent({ filter: e => e.user.id === this.id, time: 180_000 }); never finishes running
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
FluxFlu
FluxFluOP2mo ago
yes that fixed it x.x thank you so much for the help

Did you find this page helpful?