Clean code without nesting on('collect'
I'm trying to get 5 sequential infos from the user but the only way to do that was nesting a lot of callbacks. Is there another way to do it without nesting and without using forms?
Example code:
13 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
You can use
awaitMessages
instead of createMessageCollector
https://discord.js.org/#/docs/discord.js/main/class/TextChannel?scrollTo=awaitMessages (works on all text based channels)Even with the
awaitMessages
it will be nested inside the awaitMessages.then()
, no?Can be, you can also use
async/await
and avoid that.Nice, i'll try
This might be worth a look, if you are not familiar: https://discordjs.guide/additional-info/async-await.html#understanding-async-await
It isnt supposed to delete the message i just sent?
You get back a collection of collected messages, that would effectively do nothing.
This means there is no way to delete the message?
There is
You need to grab the collected message (if any) from the collection.
There is a handy
first
method on it.
https://discordjs.dev/docs/packages/collection/1.3.0/Collection:Class#firstOh, now returns in a different way than before
Sometimes its good to use a brain
Thanks god, i'm totally pleased right now
I like the abstraction