#Easy way to check if one collection (array) contains objects of another array ?

1 messages · Page 1 of 1 (latest)

lethal lake
#

Hey
i was checking https://discord.js.org/#/docs/collection/main/class/Collection if they is a easy way to check if one collection contains keys and values of another collection. I've see difference and intersec methods but i'm not sure it's what i want

can anyone can help me ?

civic prism
#

Oh hi i did try to do something like that but i dont remember my code at all, tho i remember struggling with this. I will try to reach my computer to check, maybe in around 10 minutes i will be able to give you an answer (if you are still waiting)

lethal lake
#

did you remember if you used collection method or another way ?

#

if you used premade Collection method*

civic prism
#

I remember modifying the collection to an array or something

#

But i dont quiet remember sorry, i will try do be fast

lethal lake
#

i can use some method 🤷

civic prism
#

I dont really know about that but you can try it

lethal lake
#

hum strange type error

#

Error:(19, 52) TS2345: Argument of type 'RoleResolvable[]' is not assignable to parameter of type 'string'. but i give to function an array of RoleResolvable

civic prism
#
module.exports = {

  async execute(oldMembers, newMembers) { // threadMembersUpdate event

    if (!newMembers) return;

    var arrayOld = Array.from(oldMembers);
    var arrayNew = Array.from(newMembers);

    var membresBefore = [];
    var membresAfter = [];

    for (var i in arrayOld) membresBefore.push(arrayOld[i][0]);
    for (var i in arrayNew) membresAfter.push(arrayNew[i][0]);

    for (var i in membresAfter) {
      if (!membresBefore.includes(membresAfter[i])) {
      // find the member who was added to the thread.
      };
    };

  },

};```
#

okay give me a little time to explain but i think this is what you need? (maybe not)

lethal lake
#

i see the idea, i'll check if i can't do this with a better way

#

thx

civic prism
#

Yeah it's probably not the best way to do it, but it works