Daryl Gill
Daryl Gill

Reputation: 5524

Unable to Pull messagecollector values

I'm currently having issues with iterating through a MessageCollector in the end event like so:

collector.on('end', collected => {
   message.channel.send("Searching... \r\n");
   //  .log(`Collected ${collected.size} items`);
   //console.log(collected);
   console.log(collected.first(collected.size).content);

});

Everything I have attempted is coming up undefined, the actual collection size has no limit due to wanting to log as much information as possible until timeout. However, getting the actual results from this list is proving tricky. I've tried collected.values() and such.. All undefined

Upvotes: 0

Views: 41

Answers (1)

Draityalan
Draityalan

Reputation: 710

collected.first(collected.size).content is indeed undefined, because by putting the collected size as an amount in collected.first() you will get an array of Message and so you will need to iterate on it with a forEach loop for example to get each messages content.

By the way, collected.first(collected.size) is useless because you already get all messages in collected unless you would like to get an Array from your Collection.. but Collection.array() would fit better to get an Array from a Collection.

In case you didn't noticed, a Collection extends Map.

So to iterate on all messages you collected I suggest you to do the following :

collector.on("end", collected => {
    collected.forEach(message => {
        ...
    });
})

I hope I helped you well!

Upvotes: 1

Related Questions