#filter help
34 messages · Page 1 of 1 (latest)
Collection#filter()
Identical to Array.filter(), but returns a Collection instead of an Array.
@placid elbow this didnt help ahhh
i tried js const InviteCommands = client.commands.filter(command => command.name === "invite").map((command) => command.name).join("\n"); and it just have me errors
What errors?
it just says Received one or more errors
but i have a "invite", "invites" command and im trying to sperate it from the batch of other commands
so im tryna get a const of just the invites and one without the invites if that makes sense
=== means "strictly equals"
Your filter only returns true for "invite", not "invites"
oh
idrk how to fix that then lol
String.prototype.includes()
The includes() method performs a case-sensitive search to determine whether one string may be found within another string, returning true or false as appropriate.

@placid elbow i dont want it to return a true or false i just want it to go through the available commands and include them if it finds "invite"
you would be doing that with the true or false
filter takes a predicate
so the commands that include in the name "invite" would come out to true and be mapped while the other commands that come out as false wouldnt
i see. i used ```js
const InviteCommands = client.commands.map((command) => command.name.startsWith("invite")).join("\n");
and it kinda worked just not how i wanted it to, i wanted it to actually keep the whole text and not do the whole true false thing. is there a workaround?
you can have a return statement with the .map function after the callback which would return the command name
wait
no
go back to this
but do what I said earlier in the filter
wait what
Basically:
const InviteCommands = client.commands.filter(cmd => cmd.name.startsWith("invite")).map(cmd => cmd.name).join("\n")
this would be what you would want I think
because this gets all the commands (not just invite commands) and then maps them into an array where its either true or false like [true, false, false] (for example)
basically making it so you have a boolean array
ohh i get it
thank you
because your return value is a boolean
did you figure it out?
this works!
nice