awaitMessages does not reject on timeout?

I've got the following simple code collecting a single message from a user:
const checkUserFilter = i => i.user.id === interaction.user.id;
lastInteraction.update({ 'Please enter your message below:', components: [] });
await lastInteraction.channel.awaitMessages({ checkUserFilter, time: 3000, max: 1 })
.then(receivedMessages => { console.log("We successfully made it into the then!"); })
.catch(error => {
console.log("We got to the error!");
lastInteraction.editReply({ content: 'You took too long to respond, please run the command again to provide a new message.', components: [] });
});
const checkUserFilter = i => i.user.id === interaction.user.id;
lastInteraction.update({ 'Please enter your message below:', components: [] });
await lastInteraction.channel.awaitMessages({ checkUserFilter, time: 3000, max: 1 })
.then(receivedMessages => { console.log("We successfully made it into the then!"); })
.catch(error => {
console.log("We got to the error!");
lastInteraction.editReply({ content: 'You took too long to respond, please run the command again to provide a new message.', components: [] });
});
Output upon waiting 3000 milliseconds:
We successfully made it into the then!
We successfully made it into the then!
Why is it that when the awaitMessages() times out, the then statement is still running? Shouldn't it reject and go to the .catch block?
9 Replies
d.js toolkit
d.js toolkit13mo 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
2Flow2
2Flow2OP13mo ago
I see someone posting something else here earlier today regarding awaitMessages but I don't think it is relevant.
Squid
Squid13mo ago
You have to use the errors: ['time'] option to make it reject if time expired; otherwise, it still resolves the promise
2Flow2
2Flow2OP13mo ago
Oh say what? Really?
2Flow2
2Flow2OP13mo ago
Why isn't that mentioned here?
No description
2Flow2
2Flow2OP13mo ago
Huh, and why don't other functions like awaitMessageComponent() require that argument?
monbrey
monbrey13mo ago
Just different design decisions when that was introduced Valid point to look at consistency though I think the thing there was that time is the ONLY reason a message component collector could end It either collects one component, or times out
Squid
Squid13mo ago
That function only collects one interaction ever, so it unlike awaitMessages() which can return just an empty collection instead of a populated one, that collector's type would have to be changed depending on whether timeouts error since it would need to return null or something similar awaitReactions works the same as awaitMessages since both can collect multiple of whatever structure, so awaitMessagecomponent is actually the odd one out
2Flow2
2Flow2OP13mo ago
Gothca. Okay, well thanks for letting me know about the argument that needed to be passed! That solves my issue!
Want results from more Discord servers?
Add your server