Calling promise function twice causes error

I have the following function that should await either a message from the user, or await a button click.
async function awaitInput() {
// awaits a response from the user. Returns either the message
// string or the button id.
const inputFilter = (m) => {
return m.author.id === interaction.user.id;
};
const btnFilter = async (i) => {
await i.deferUpdate();
return i.user.id === interaction.user.id;
};
// const message listed at the bottom of the post
const promises = [
interaction.channel.awaitMessages({
filter: inputFilter,
max: 1,
time: 60_000,
errors: ["time"],
}),
message.awaitMessageComponent({
filter: btnFilter,
ComponentType: ComponentType.Button,
time: 120_000,
}),
];

return Promise.any(promises).then((res) => {
if (res instanceof Collection) {
res.first().delete();
return res.first().content;
} else {
return res.customId;
}
});
}
async function awaitInput() {
// awaits a response from the user. Returns either the message
// string or the button id.
const inputFilter = (m) => {
return m.author.id === interaction.user.id;
};
const btnFilter = async (i) => {
await i.deferUpdate();
return i.user.id === interaction.user.id;
};
// const message listed at the bottom of the post
const promises = [
interaction.channel.awaitMessages({
filter: inputFilter,
max: 1,
time: 60_000,
errors: ["time"],
}),
message.awaitMessageComponent({
filter: btnFilter,
ComponentType: ComponentType.Button,
time: 120_000,
}),
];

return Promise.any(promises).then((res) => {
if (res instanceof Collection) {
res.first().delete();
return res.first().content;
} else {
return res.customId;
}
});
}
The first time works as intended. Either button clicks or message inputs cause the customId or message content to be available and used. However, if I try to call the function twice, I get this error:
node:events:504 // gateway timeout error??
{
message: 'Interaction has already been acknowledged.',
code: 40060
},
code: 40060,
status: 400,
method: 'POST',
url: '<<url that leads to the object below>>'
}

{"message": "405: Method Not Allowed", "code": 0}
node:events:504 // gateway timeout error??
{
message: 'Interaction has already been acknowledged.',
code: 40060
},
code: 40060,
status: 400,
method: 'POST',
url: '<<url that leads to the object below>>'
}

{"message": "405: Method Not Allowed", "code": 0}
The code has stopped working ever since implementing this function, so I think it's likely I am missing some problem with it. However, it's also possible that it's not the function that causes the problem and it's something else instead. I'd appreciate it if someone else could look at the function and tell me if there's any problems with the execution. The message variable is the following:
const message = await interaction.editReply({
embeds: [replyEmbed],
components: [btnFirstRow, btnSecondRow, cancelRow],
});
const message = await interaction.editReply({
embeds: [replyEmbed],
components: [btnFirstRow, btnSecondRow, cancelRow],
});
2 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Luca | LeCarbonator
There is one other alternative I can think of: I'm trying to make a submenu system, where you have a main interface, but use buttons/inputs to manipulate values on the main embed so perhaps there's a conflict between awaiting message components on the main embed while also awaiting components on the submenus I have no clue if that truly conflicts though, I'd have to test extensively for that hmm. How do I clear both collectors after Promise.any() resolves/rejects? I see, I suppose that makes sense alright, I'll try that then so using regular collectors worked so far. One problem I now have is with collector.stop() Since I only want one message or one button press, I stop them as soon as they collect. But how do I stop both collectors if only one of them collected something? I seem to trigger the "end" eventlistener by doing this the reason? oh, I see what you mean