【发布时间】:2021-08-29 07:50:07
【问题描述】:
无法读取属性“拆分”,我不知道如何解决此问题。
(node:21492) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of undefined
at Client.<anonymous> (C:\Users\bradl\Desktop\account-generator-2\index.js:155:27)
at Client.emit (events.js:376:20)
at MessageCreateHandler.handle (C:\Users\bradl\Desktop\account-generator-2\node_modules\discord.js\src\client\websocket\packets\handlers\MessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:\Users\bradl\Desktop\account-generator-2\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:108:65)
at WebSocketConnection.onPacket (C:\Users\bradl\Desktop\account-generator-2\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:336:35)
at WebSocketConnection.onMessage (C:\Users\bradl\Desktop\account-generator-2\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:299:17)
at WebSocket.onMessage (C:\Users\bradl\Desktop\account-generator-2\node_modules\ws\lib\event-target.js:120:16)
at WebSocket.emit (events.js:376:20)
at Receiver.receiverOnMessage (C:\Users\bradl\Desktop\account-generator-2\node_modules\ws\lib\websocket.js:789:20)
at Receiver.emit (events.js:376:20)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:21492) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:21492) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
在我得到错误部分的地方添加命令
if(command === "add") {
if (!message.member.hasPermission("ADMINISTRATOR")) return message.reply("Sorry, you can't do it, you are not an admin!");
let messageArray = message.content.split(" ");
let args = messageArray.slice(1);
var acc = args[1].split(":");
【问题讨论】:
-
向我们展示你的 index.js 大约在第 155 行。错误就在那里。你打电话给
splitundefined而不是string -
@Sysix 好了,抱歉我早该想到的
-
message.content是可选的。你也在猜测每个内容至少有一个空格字符。 -
尝试控制台
message.content和args[1]检查它们是否是字符串 -
记录
args并验证是否有第二个元素
标签: javascript node.js discord.js undefined