Discord Message.js正在抛出错误“;无法读取属性';内容';“未定义”的定义;

Discord Message.js正在抛出错误“;无法读取属性';内容';“未定义”的定义;,discord,discord.js,Discord,Discord.js,我正在尝试重新构造message.js,使其工作更顺畅,并允许在命令中使用别名。我从一个教程中逐字复制了几乎所有的代码,只是修改了一些东西来适应我的机器人,因为我不太确定这样做的最佳方式。现在,它不仅对命令作出反应,而且对发送的每一条消息作出反应,并在标题中抛出错误。我不知道为什么内容没有定义,如果有人能帮上忙那就太好了 这是我的message.js(我删除了以前的数据库内容,因为它只会阻塞代码块,与问题无关) const profileModel=require(“../models/prof

我正在尝试重新构造message.js,使其工作更顺畅,并允许在命令中使用别名。我从一个教程中逐字复制了几乎所有的代码,只是修改了一些东西来适应我的机器人,因为我不太确定这样做的最佳方式。现在,它不仅对命令作出反应,而且对发送的每一条消息作出反应,并在标题中抛出错误。我不知道为什么内容没有定义,如果有人能帮上忙那就太好了

这是我的message.js(我删除了以前的数据库内容,因为它只会阻塞代码块,与问题无关)

const profileModel=require(“../models/profileSchema”);
const config=require('../config.json');
module.exports=异步(不一致、客户端、消息)=>{
//命令处理程序启动
让prefix=config.prefix;
如果(!message.content.startsWith(prefix)| | message.author.bot)返回;
const args=message.content.slice(prefix.length).split(+/+/g);
const cmd=args.shift().toLowerCase();
const command=client.commands.get(cmd)| client.commands.find(a=>a.aliases&&a.aliases.includes(cmd));
if(!command)返回message.channel.send(“:x:这不是有效的命令”);
执行(消息、args、cmd、客户端、Discord、profileData);
}
以下是本文档中曾经有效的代码,以供参考

module.exports = (client, message) => {
    
    if (message.author.bot) return;
  
    
    if (message.content.indexOf(client.config.prefix) !== 0) return;
  
    
    const args = message.content.slice(client.config.prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();
  
    
    const cmd = client.commands.get(command);
  
    
    if (!cmd) return;
  
    
    cmd.run(client, message, args);
};
我添加的只是一个前缀检查

let prefix = config.prefix;
    if (!message.content.startsWith(prefix) || message.author.bot) return;
并使用

const command = client.commands.get(cmd)  || client.commands.find(a => a.aliases && a.aliases.includes(cmd));

欢迎来到SO。它并不抱怨
内容
未定义。它抱怨(我相信)
消息
是未定义的,因为它是唯一用content属性/属性引用的对象。错误是否指定了任何特定行?
消息
未定义。请显示执行此函数的代码。@ewong Yes在第8行检查消息是否以前缀开头,前缀也是第一次使用message.content,如果(!message.content.startsWith(prefix)| | message.author.bot)返回;请显示您在何处执行此文件导出的函数。@Saoul我很高兴您能修复它。经验法则是永远不要使用你不懂的代码,否则你将被迫进入这些情况。