FluxFlu
FluxFlu
DIAdiscord.js - Imagine an app
Created by FluxFlu on 12/29/2024 in #djs-questions
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 =)
25 replies