简体   繁体   中英

Cannot read property 'send' of undefined discord.js warn command

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM