-3

I have the following code which is contained within a much larger if statement block:

message.reply({ embeds: [multipleUsersEmbedFunction("Multiple Users Found", `The following users were found:\n${string}`, members)], components: [actionRow] }).then((embedMessage) => {
              const collector = embedMessage.createMessageComponentCollector({ time: 5000 });
              collector.on("collect", async (i) => {
                console.log(i);
                return members[Number(i.customId)];
              });
            });

At the bottom of my code I have the following: return undefined;, which is used by other if else statements which do not return anything.

However, this message collector (discord.js) of course should wait 5 seconds before returning undefined, however my code is still instantly returning undefined.

How would I circumvent this?

  • 1
    Why is the callback function `async`? It doesn't contain an `await` call? – jabaa Apr 21 '22 at 20:09
  • Does this answer your question? [How do I convert an existing callback API to promises?](https://stackoverflow.com/questions/22519784/how-do-i-convert-an-existing-callback-api-to-promises) – jabaa Apr 21 '22 at 20:10

1 Answers1

-1

If the reply that you are waiting is async, you must to considere using the await before the reply. For example, if the reply use time or timer function, it's very posible that await is a solution for you.

  • if it uses promises, yes. callbacks, no – Joe Apr 21 '22 at 20:17
  • `await` is not a solution to this particular problem because the OP is using `collector.on(...)` which is NOT promise based and then trying to return a value from that event's callback which makes the return value go nowhere. – jfriend00 Apr 21 '22 at 21:39