Не удается прочитать свойство ‘send’ неопределенной discord.js команда warn

#javascript #discord #discord.js #bots

#javascript #Discord #discord.js #боты

Вопрос:

Я выполняю команду warn и получил эту ошибку:

 cannot read property 'send' of undefined
  

Я не слежу за видео YT, я создаю команду сам, и я не знаю, что я делаю. Я очень новичок в написании кода для discord bot, поэтому, если бы вы могли мне помочь, это было бы здорово

Вот мой код:

 bot.on('message', message => {
    if (!message.content.startsWith(PREFIX)) return;
    let args = message.content.substring(PREFIX.length).split(' ');
    if (message.author.bot) return;

    switch (args[0]) {
        case 'warn':
            if (message.channel.type === 'dm') {
                return message.reply('I can't execute that command inside DMs!');
            }
            const person = message.mentions.members.first();

            if (!person) return message.reply("Please mention a user");
            if (!message.author.hasPermission('MANAGE_MESSAGES'))
                return message.reply("You don't have permissions to warn members");
            var arg = message.cleanContent.split(" ").slice(2).join(" ")
            if(!arg) message.channel.send('Why are you warning the user for?')
            
            
                message.person.send(`You have been warned from **${message.guild.name}** for ${arg}`)
            
            break;


    }


});
  

Также, если в моем коде что-то еще не так, пожалуйста, скажите мне

Ответ №1:

Один из операторов lasts является message.person.send(`You have been warned from **${message.guild.name}** for ${arg}`) . Вы обращаетесь к «person» в отправленном сообщении, но «person» в сообщении не существует (поэтому оно не определено). Вы должны заменить message.person на person , как вы определили это ранее.