gpt4 book ai didi

javascript - 类型错误 : Cannot read property 'id' of undefined (also 'startWith' )

转载 作者:行者123 更新时间:2023-12-01 01:39:20 25 4
gpt4 key购买 nike

我收到的错误:(我也收到与“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);

}

};

最佳答案

您看到的错误是因为message没有authorcontent字段。

处理如下场景:

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);
}

};

查看发送消息的代码,并尝试调试为什么它没有发送预期的字段。

关于javascript - 类型错误 : Cannot read property 'id' of undefined (also 'startWith' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52556557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com