I keep on getting this error. I am making a welcomer bot for my discord server and I am trying to implement a role adding function when somebody joins and keep on getting that error.
const channel = member.channels.cache.find(ch => ch.name === 'welcome');
if (!channel) return;
channel.send(`Welcome to the Server, ${member}`);
});
bot.on('guildMemberAdd', member => {
role = member.addRole(member.guild.roles.find("name","member"));
});```
According to Discord.js Documentation , I think you can implement with:
member.roles.add(member.guild.roles.cache.find(x => x.name == "scriptkiddie"), "Reason");
Something like this, as you can fetch Guild Roles with
member.guild.roles.cache
I believe roles
is not the value you expect it to be. If it was an array, or any object with a find
method, you wouldn't get that error. Log the value of roles
to determine what data type it is, then change accordingly.
console.log(member.guild.roles)
In the latest version of discord.js you must do member.guild.roles.cache
to get the collection.
Then do member.guild.roles.cache.find(....)
with whatever you want to find :)
Hope this helps!
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.