Is there a way to simultaneously use awaitMessages and awaitMessageComponent?

I'm currently using a do while loop to modify entries in a list. If the user enters "done", it exits that loop. However, I am curious if there's a way to perform that action with a button instead. So the process would be as follows: - Display list - Await message and append entry to the list - ... but if a button is pressed instead, exit the loop. Up until now, I have worked exclusively with the two methods mentioned in the title. The problem with collector.on listeners is that they do not work in a while loop, since they can't be awaited. If collector.on listeners are the way to go, I'd like to know if it's possible to place them in a promise.
7 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
souji
souji3y ago
not too sure what you are asking - promisified collectors is exactply what await* is and collectors in turn are just temporary event listeners
Luca | LeCarbonator
well, the problem is using awaitMessages and awaitMessageComponent simultaneously so if either one fires, perform the corresponding action
d.js docs
d.js docs3y ago
mdn Promise.any() The Promise.any() method takes an iterable of promises as input and returns a single Promise. This returned promise fulfills when any of the input's promises fulfills, with this first fulfillment value. It rejects when all of the input's promises reject (including when an empty iterable is passed), with an AggregateError containing an array of rejection reasons.
Luca | LeCarbonator
... javascript surprises me everyday. I'll read up on it! thanks!
souji
souji3y ago
that should do the trick - you will need to do some validation to know which promise fulfilled (should be easy enough with an instance check) alternatively you can wrap the promises into some structure that exposes it's type; that mostly depends on personal preference
Luca | LeCarbonator
yeah, this is more than enough info to start experimenting. Since this is solved, I'll close the post now bueno thanks for your advice
Want results from more Discord servers?
Add your server