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•3y ago
Message Not Public
Sign In & Join Server To View
not too sure what you are asking - promisified collectors is exactply what await* is
and collectors in turn are just temporary event listeners
well, the problem is using awaitMessages and awaitMessageComponent simultaneously
so if either one fires, perform the corresponding action
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.
... javascript surprises me everyday. I'll read up on it! thanks!
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
yeah, this is more than enough info to start experimenting. Since this is solved, I'll close the post now thanks for your advice