Javascript TypeError:无法读取属性';id';未定义的(也可从';开始)

Javascript TypeError:无法读取属性';id';未定义的(也可从';开始),javascript,discord,discord.js,Javascript,Discord,Discord.js,我得到的错误:(我也得到了与“startWith”相同的错误)。我真的不确定我做错了什么,我不是一个真正的职业选手,所以我需要一些帮助。多谢各位 TypeError: Cannot read property 'id' of undefined at module.exports.message (/root/dvstin.xyz/events/message.js:6:21) at Client.client.on.args (/root/dvstin.xyz/druggy2.js:14:39

我得到的错误:(我也得到了与“startWith”相同的错误)。我真的不确定我做错了什么,我不是一个真正的职业选手,所以我需要一些帮助。多谢各位

TypeError: Cannot read property 'id' of undefined
at module.exports.message (/root/dvstin.xyz/events/message.js:6:21)
at Client.client.on.args (/root/dvstin.xyz/druggy2.js:14:39)
at Client.emit (events.js:187:15)
at MessageCreateHandler.handle (/root/dvstin.xyz/node_modules/discord.js/src/client/websocket/packets/handlers/MessageCreate.js:9:34)
at WebSocketPacketManager.handle (/root/dvstin.xyz/node_modules/discord.js/src/client/websocket/packets/WebSocketPacketManager.js:103:65)
at WebSocketConnection.onPacket (/root/dvstin.xyz/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:333:35)
at WebSocketConnection.onMessage (/root/dvstin.xyz/node_modules/discord.js/src/client/websocket/WebSocketConnection.js:296:17)
at WebSocket.onMessage (/root/dvstin.xyz/node_modules/ws/lib/event-target.js:120:16)
at WebSocket.emit (events.js:182:13)
at Receiver._receiver.onmessage (/root/dvstin.xyz/node_modules/ws/lib/websocket.js:137:47)
这是我正在使用的代码:

module.exports = message => {
// Define client
const Discord = require("discord.js");
const client = message.client;
// Check who, and the prefix being used

if (message.author.id === "") return;
if (!message.content.startsWith(client.settings.prefix)) return;
// Define command
const command = message.content
    .split(" ")[0]
    .slice(client.settings.prefix.length)
    .toLowerCase();
// Define command paramaters
const params = message.content.split(" ").slice(1);
let cmd;
if (client.commands.has(command)) {
    cmd = client.commands.get(command);
}
// If command, run that command
if (cmd) {

    cmd.run(client, message, params);

}

};

您看到的错误是因为
消息
没有
作者
内容
字段

按以下方式处理场景:

module.exports = message => {
   // Define client
   const Discord = require("discord.js");
   const client = message.client;

   console.log(message); // <--- Check this console. 
   // Check who, and the prefix being used

    if (message && message.author && message.author.id === "") return;
        if (message && message.content && !message.content.startsWith(client.settings.prefix)) return;
            // Define command
            const command = message.content
                .split(" ")[0]
                .slice(client.settings.prefix.length)
                .toLowerCase();
            // Define command paramaters
            const params = message.content.split(" ").slice(1);
            let cmd;
             if (client.commands.has(command)) {
            cmd = client.commands.get(command);
        }
        // If command, run that command
        if (cmd) {

            cmd.run(client, message, params);
        }

    };
module.exports=消息=>{
//定义客户端
const Discord=require(“Discord.js”);
const client=message.client;

console.log(message);//您看到的错误是因为
消息
没有
作者
内容
字段

按以下方式处理场景:

module.exports = message => {
   // Define client
   const Discord = require("discord.js");
   const client = message.client;

   console.log(message); // <--- Check this console. 
   // Check who, and the prefix being used

    if (message && message.author && message.author.id === "") return;
        if (message && message.content && !message.content.startsWith(client.settings.prefix)) return;
            // Define command
            const command = message.content
                .split(" ")[0]
                .slice(client.settings.prefix.length)
                .toLowerCase();
            // Define command paramaters
            const params = message.content.split(" ").slice(1);
            let cmd;
             if (client.commands.has(command)) {
            cmd = client.commands.get(command);
        }
        // If command, run that command
        if (cmd) {

            cmd.run(client, message, params);
        }

    };
module.exports=消息=>{
//定义客户端
const Discord=require(“Discord.js”);
const client=message.client;

console.log(message);//验证对象的字段时,始终应检查对象

接下来是一个代码示例

In:
if(message.author.id==“”)返回;

您应该执行以下操作:
if(message.author&&message.author.id===“”)返回;

如果您不确定哪条消息不是空的,则必须执行以下操作:
if(message&&message.author&&message.author.id===“”)返回;


我希望对您有所帮助

在验证对象的字段时,您应该始终检查对象

接下来是一个代码示例

In:
if(message.author.id==“”)返回;

您应该执行以下操作:
if(message.author&&message.author.id===“”)返回;

如果您不确定哪条消息不是空的,则必须执行以下操作:
if(message&&message.author&&message.author.id===“”)返回;


我希望对您有所帮助。

意味着
消息。作者未定义。调试它并查看消息包含的内容。意味着
消息。作者未定义。调试它并查看消息包含的内容。非常感谢!但是我仍然收到一个错误,但在另一行。/root/dvstin.xyz/events/message.js:13.split(“”[0]^TypeError:无法读取的属性“拆分”undefined@Universal正如我在回答中所说的,请检查
消息
对象的来源,以及为什么它没有提供所有预期字段。非常感谢!但是我仍然收到一个错误,但在另一行。/root/dvstin.xyz/events/message.js:13.拆分(“”[0]^TypeError:无法读取的属性“拆分”undefined@Universal正如我在回答中所说,请检查
消息
对象来自何处,以及为什么它没有提供所有预期字段。非常感谢!非常感谢!