T
T
TipoImya2020-09-01 12:42:29
JavaScript
TipoImya, 2020-09-01 12:42:29

When deleting the user id from the database, an error occurs. What is the problem?

Fams.findOne({FamilyName: famuly_name}, async(err, fam) => {
                if(err) console.log(err);
                if(!fam) {
                    return await message.channel.send("Данной семьи нету!")
                }
                fam.markModified('FamilyInfo')
                if(fam.FamilyInfo.FamilyZams.includes(user.id)) {
                    await message.delete();
                    let remove_userZam = fam.FamilyInfo.FamilyMembers.indexOf(user.id);
                    let remove_userZamDescr = fam.FamilyInfo.FamilyMembersDescr.indexOf(`<@${user.id}>`);
                    fam.FamilyInfo.FamilyZams.splice(remove_userZam, 1)
                    fam.FamilyInfo.FamilyZamDescr.splice(remove_userZamDescr, 1)
                    fam.save().catch(err => console.log(err))
                    
                    let EmbedOfKickZam = new Discord.MessageEmbed()
                    .setTitle(`Информация об действии создателя/заместителя.`)
                    .setColor(`RED`)
                    .addField(`**Название семьи:**`, `\`Семья:\` ${families[0]}.`, true)
                    .addField(`**Кикнул лидер:**`, `<@${message.author.id}>.`, true)
                    .addField(`**Кикнутый заместитель:**`, `<@${user.id}>.`, true)
                    .addField(`**Действие:**`, `Кик заместителя.`, true)
                    if(message.createdAt.getSeconds() <= 9) {
                        EmbedOfKickZam.addField(`**Время кика:**`, `${message.createdAt.getHours()}:${message.createdAt.getMinutes()}:0${message.createdAt.getSeconds()}`, true)
                        .then(msg => msg.delete({timeout: 7000}))
                    } else {
                        EmbedOfKickZam.addField(`**Время кика:**`, `${message.createdAt.getHours()}:${message.createdAt.getMinutes()}:${message.createdAt.getSeconds()}`, true)
                        .then(msg => msg.delete({timeout: 7000}))
                    }


Error: UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'splice' of undefined. What is the problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question