Discord.js : Reaction.message.guild.members.find Is Not A Function
Solution 1:
If you're using Discord.js v12 (the latest version), Guild#members
is a GuildMemberManager
, not a Collection
like in v11.
To access the collection use the cache
property.
Another difference is that Collection
does not support finding something by key and value like that. However, it does support getting objects by its id
:
reaction.message.guild.members.cache.get(user.id)
Note that to find an object by another key, you would need to use this:
reaction.message.guild.members.cache.find(member => member.someProperty === theValue)
You might also want to check that the reaction was done in a guild (unless you're using intents and aren't using the DIRECT_MESSAGE_REACTIONS
intent). People can add reactions to messages in DMs as well, so reaction.message.guild
may be undefined
.
Solution 2:
If you are using latest version, here is an example:
They have also changed addRole to: roles.add in v12
let role = message.guild.roles.cache.find(role => role.name === 'somerolename');
reaction.message.guild.member(user).roles.add(role.id).catch(console.error);
https://discordjs.guide/additional-info/changes-in-v12.html#roles
Solution 3:
According to the doc, you can use reaction.users
to get a collection of users who reacted to the message.
The collection will look something like this:
Collection(n)[Map] {
'id_of_user_who_reacted' => <ref*1> ClientUser{
id: 'id_of_user_who_reacted',
username: String,
discriminator:String
...
}
}
Then you can use the map() method of the Collector type to get the user id
console.log(reaction.users.map(user => user.id))
which will return an array that will look like this:
['id', 'id', 'id']
Then you can change the role of those users.
Post a Comment for "Discord.js : Reaction.message.guild.members.find Is Not A Function"