#keyArray
1 messages ยท Page 1 of 1 (latest)
ok so a thread
so you should do that with your collection
your collection being oldMember.roles.cache
so like this ? ```js
const oldRoles = oldMember.roles.cache().filter(x => !options.excludedroles.includes(x)).filter(x => !newMember.roles.cache().includes(x))
const keyArray = [...oldRoles.keys()]```
that should work right ?
x is a role
hmm
it was a string before
.
.
don't know what else to say, really
oldMember.roles.cache is the collection you want the keys of
but i need to check if the newMember has the role or not
so to get the keys before you used oldMember.roles.cache.keyArray() now that's gone
so you instead spread the .keys() into an array as i explained
then i don't understand why you are using an key array to begin with?
you want to check if the collection has one of multiple roles, of which you have the ids?
whole code
okay?
i still don't see what any of that has to do with my questions - or your initial question
what is it that you are trying to do here?
oh wait i messed up
so, again
const oldRoles = oldMember.roles.cache.keyArray().filter(x => !options.excludedroles.includes(x)).filter(x => !newMember.roles.cache.key().includes(x))
that was your code
now .keyArray() does not exist
instead, spread the cache's oldMember.roles.cache keys iterator oldMember.roles.cache.keys() into an array
quoting myself here:
https://discord.js.org/#/docs/collection/stable/class/Collection?scrollTo=keys returns an iterator, which you can collect into an array
const keyArray = [...myCollection.keys()]- to name one example for a collection instance
so It checks when a member gets the role add the member to the emebed then when removed remove it from the embed
const oldRoles = oldMember.roles.cache.keys().filter(x => !options.excludedroles.includes(x)).filter(x => !newMember.roles.cache.keys().includes(x))``` this ?
make it into keys ?
try to read my answer more carefully
ok
i am learning atm and i am confused
oldMember.roles.cache.keyArray() <-- this is what i'm telling you how to replace
ignore the rest for now
hmmmmmm
so do
instead, spread the cache's
oldMember.roles.cachekeys iteratoroldMember.roles.cache.keys()into an arrayquoting myself here:
https://discord.js.org/#/docs/collection/stable/class/Collection?scrollTo=keys returns an iterator, which you can collect into an array
const keyArray = [...myCollection.keys()]- to name one example for a collection instance
and then filter, as you did before
ok i got it
const oldRoles = [...oldMember.roles.cache.keys()].filter(x => ![...newMember.roles.cache.keys()].includes(x))``` this right ?
should work
Umm....... ?
maybe? i'd personally advise you against using keys here, it complicates the code and your execution time
you can #filter the collection directly
old.roles.cache.filter(role => !new.roles.cache.filter.has(role.id)) or similar
#has is a direct key lookup and much, much faster than a full iteration on every single iteration (which is what you are doing here)
ok i see
and Collection#filter directly iterates the map, instead of first iterating it to convert it to an array and then iterating it again
oh
also is js role.members.length === 0 not a function ?
rosterembed.addField("**" + role.name.toUpperCase() + "**", role.members.length === 0 ? "> No one has this Role" : ">>> " + role.members.map(member => `<@${member.user.id}> | \`${member.user.tag}\``).join("\n").substr(0, leftnum))``` so if none has the role it should say "No one has this Role" but it doesnt for some reason
<:_:874569322742308864> Role#members
The cached guild members that have this role
Type: Collection
<Snowflake, GuildMember>
returns a collection, collections don't have a .length
<:_:874569296821501952> Collection
A Map with additional utility methods. This is used throughout discord.js rather than Arrays for anything that has an ID, for significantly improved performance and ease-of-use.
#size is used for maps
so ```js
role.members.size === 0
try it
yeah, you tell it to do that
so i said if size == 0 say " No one has this Role"
what's your new code?
rosterembed.addField("**" + role.name.toUpperCase() + "**", role.members.size === 0 ? "> No one has this Role" : ">>> " + role.members.map(member => `<@${member.user.id}> | \`${member.user.tag}\``).join("\n").substr(0, leftnum))
console.log(role.members)
ok i fixed it