How to fix: TypeError: Cannot read property 'name' of undefined?

I did bot for discord, these lines were responsible for the results of a role when entering a new player on the server, but something went wrong. Crashes error: TypeError: Cannot read property 'name' of undefined
Here is the code:
const shell = module.require("discord.js");
const bot = new shell.Client();

var newPlayers = [];
var newPlayer = {};

bot.on('guildMemberAdd', (member) =>
{
 member.send('Welcome');
 member.addRole(member.roles.some(val => val.name === 'Player'));
});
April 19th 20 at 12:25
1 answer
April 19th 20 at 12:27
Solution
This error may occur if one of the elements of the array member.roles recorded the value undefined. See what comes in the member.
Understood nothing :/ - Robert_Bednar7 commented on April 19th 20 at 12:30
@Robert_Bednar7, in this case, I have to disappoint you - you need to learn the Russian language and learn to read, not to write bots. - cydney_Flatl commented on April 19th 20 at 12:33

Find more questions by tags JavaScript