This is a code example I am working with:
.sort((a, b) => b.createdAt - a.createdAt)
After fetching and filtering messages from a channel (which has a total of 8 messages), the filter operation returns a collection that may not be sorted in order.
How can I organize my messages so that the given formula functions correctly?
(Please disregard the .first() in the provided screenshot)
The collection contains 4 messages, where using .first() simply retrieves the initial message. My objective is to extract values from all four messages for inclusion in my embed like this:
newchannel.fetchMessages().then(messages => {
var valuesA = messages.filter(m => m.author.id === message.author.id).first();
var valuesB = messages.filter(m => m.author.id === message.author.id).second();
var valuesC = messages.filter(m => m.author.id === message.author.id).third();
var valuesD = messages.filter(m => m.author.id === message.author.id).fourth();
const embed = {
"fields": [
{
"name": "Type of code:",
"value": valuesA.content,
"inline": true
},
{
"name": "Type of code:",
"value": valuesB.content,
"inline": true
},
{
"name": "Type of code:",
"value": valuesC.content,
"inline": true
},
{
"name": "Type of code:",
"value": valuesD.content,
"inline": true
}
]
};
}
While this snippet doesn't contain the complete code or entire embed setup, it provides all necessary details.
If you have any queries, feel free to ask in the comments below.