0

I am making a warn command and got this error:

cannot read property 'send' of undefined

I am not following a YT video I'm making the command myself and I don't know what I am doing. I am very new to coding and coding a discord bot so If you could help me that will be great

Here is my code:

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;


    }


});

Also if there is anything else wrong with my code please tell me

1 Answer 1

1

One of the lasts statements is message.person.send(`You have been warned from **${message.guild.name}** for ${arg}`). You are accessing "person" in the sent message, but "person" doesn't exist in a message (so it is undefined). You should replace message.person by person, as you defined it before.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.