Im trying to assign code a discord bot to give someone a role whenever they enter a server. This is my code right now:
client.on('guildMemberAdd', (member) => {
let role = guild.roles.cache.find(r => r.name === "Admin");
console.log(role);
if(!role){
console.log("Role doesen't exist.");
}
member.roles.add(role);
});
I tried running it, and this line executed: console.log("Role doesen't exist.");. I then went on to print the role variable, and it was undefined. What's the problem?