简体   繁体   English

无法读取未定义的 discord.js 警告命令的属性“发送”

[英]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.我不是在关注 YT 视频,而是自己发出命令,但我不知道自己在做什么。 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}`) .最后的语句之一是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).您正在发送的消息中访问“person”,但消息中不存在“person”(因此未定义)。 You should replace message.person by person , as you defined it before.你应该用person替换message.person ,就像你之前定义的那样。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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