R
R
Rich2020-04-16 22:31:01
JavaScript
Rich, 2020-04-16 22:31:01

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

I made a bot for a discord, these lines were responsible for issuing a role when a new player entered the server, but something went wrong. An error is thrown: TypeError: Cannot read property 'name' of undefined
Here is the code:

const Discord = module.require("discord.js");
const bot = new Discord.Client();

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

bot.on('guildMemberAdd', (member) =>
{
    member.send('Добро пожаловать');
    member.addRole(member.roles.some(val => val.name === 'Игрок'));
});

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-04-16
@oldzhmih

This error can occur if one of the elements of the member.roles array contains the value undefined. See what comes in member.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question