Reputation:
I receive the following error:
C:\Users\(private)\discord\bots\(private)\node_modules\@discordjs\collection\dist\index.js:161
if (fn(val, key, this))
^
TypeError: fn is not a function
Code related to the error:
// This is in the discord.js module
find(fn, thisArg) {
if (typeof thisArg !== 'undefined')
fn = fn.bind(thisArg);
for (const [key, val] of this) {
if (fn(val, key, this))
return val;
}
return undefined;
}
And my code if it helps. I've dumbed it down to a simple console.log for testing purposes:
\\ not everything is here, just the important stuff.
const target = message.guild.members.cache.find(args[0])
console.log(target.roles.forEach(role => console.log(role.id)))
Upvotes: 3
Views: 100
Reputation: 23179
It's because .find()
accepts a function as an argument but you provided a string. It returns the first item where the given function returns a truthy value. You could find a member by checking if their id
property is the same as args[0]
:
message.guild.members.cache.find((member) => member.id == args[0])
But you should probably use the .get()
method, which is faster, to get a member by their ID:
const target = message.guild.members.cache.get(args[0])
Upvotes: 1