无法读取属性"拆分",不和谐帐户生成器机器人



无法读取属性"split",我不知道该怎么解决。

(node:21492) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'split' of undefined
at Client.<anonymous> (C:UsersbradlDesktopaccount-generator-2index.js:155:27)
at Client.emit (events.js:376:20)
at MessageCreateHandler.handle (C:UsersbradlDesktopaccount-generator-2node_modulesdiscord.jssrcclientwebsocketpacketshandlersMessageCreate.js:9:34)
at WebSocketPacketManager.handle (C:UsersbradlDesktopaccount-generator-2node_modulesdiscord.jssrcclientwebsocketpacketsWebSocketPacketManager.js:108:65)
at WebSocketConnection.onPacket (C:UsersbradlDesktopaccount-generator-2node_modulesdiscord.jssrcclientwebsocketWebSocketConnection.js:336:35)
at WebSocketConnection.onMessage (C:UsersbradlDesktopaccount-generator-2node_modulesdiscord.jssrcclientwebsocketWebSocketConnection.js:299:17)
at WebSocket.onMessage (C:UsersbradlDesktopaccount-generator-2node_moduleswslibevent-target.js:120:16)
at WebSocket.emit (events.js:376:20)
at Receiver.receiverOnMessage (C:UsersbradlDesktopaccount-generator-2node_moduleswslibwebsocket.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(":");   

如果你在nodejs v14中,你可以制作:

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(":");

acc未定义,但没有错误。

如果你在nodejs v12中,你可以做一个简单的条件:

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);
if(!args[1]) return;
var acc = args[1].split(":");   

最新更新