TypeError: reaction.message.guild.roles.cache is not a function.
I don't understand what's wrong in my code below:
client.on('messageReactionAdd', (reaction, user) => {
if (user.bot) return;
var roleName = reaction.emoji.name;
console.log(roleName);
var role = reaction.message.guild.roles.cache(
(role) => role.name.toLowerCase() === roleName.toLowerCase()
);
var member = reaction.message.guild.members.find(
(member) => member.id === user.id
);
if (member.roles.has(role.id)) {
member
.removeRole(role.id)
.then((member) => {
console.log(
'Removed' + member.user.username + ' from the ' + role.name + ' role.'
);
})
.catch((err) => console.error);
} else {
member
.addRole(role.id)
.then((member) => {
console.log(
'Added ' + member.user.username + ' to the ' + role.name + ' role.'
);
})
.catch((err) => console.error);
}
});
If you are trying to react to uncached messages you need to add partials.
You can find more information here: Partials
I would recommend asking the guys over on Discord.js
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.