JavaScript(Node.js)仅将String内容解释为Linux节点上的Object

时间:2016-07-14 20:28:09

标签: javascript node.js linux string typeerror

我的Discord.io机器人遇到了麻烦。我试图让它在Linux服务器上运行,但是,Node.js的Linux版本经常将字符串的内容解释为单独的对象,导致以下TypeError:

TypeError: Object IT'S ALIVE has no method 'startsWith' at DiscordClient.bot.getMessages.channel (/root/Davixxabots/Daru/Darubot.js:182:17) at DiscordClient.emit (events.js:106:17) at DiscordClient.handleWSMessage (/root/Davixxabots/Daru/node_modules/discord.io/lib/index.js:1049:11) at WebSocket.emit (events.js:98:17) at Receiver.ontext (/root/Davixxabots/Daru/node_modules/ws/lib/WebSocket.js:841:10) at /root/Davixxabots/Daru/node_modules/ws/lib/Receiver.js:536:18 at Receiver.applyExtensions (/root/Davixxabots/Daru/node_modules/ws/lib/Receiver.js:371:5) at /root/Davixxabots/Daru/node_modules/ws/lib/Receiver.js:508:14 at Receiver.flush (/root/Davixxabots/Daru/node_modules/ws/lib/Receiver.js:347:3) at Receiver.opcodes.1.finish (/root/Davixxabots/Daru/node_modules/ws/lib/Receiver.js:541:12)

以下是带有错误的代码:

if (message.toString().startsWith("/gamechange ") && userID == config.ownerID) {



                        //messageSplit = message.split("/gamechange");
                        var messageSplit = message.substring(message.indexOf("/gamechange ")+ 11);

                        if (messageSplit == "" || messageSplit == " ") {

                            bot.setPresence({ game:""});

                        }

                    bot.setPresence({

                            game: messageSplit

                    });

                    deleteCmdMessage(channelID, message);
                    log("Changed game to: \" " + messageSplit + ".");



            }

它在Windows上工作得非常好。

提前感谢您提供的任何帮助!

1 个答案:

答案 0 :(得分:1)

  

“...经常将字符串的内容解释为单独的对象,”不知道你的意思,但由于你的字符串没有startsWith()方法,看起来你只是使用旧版本的节点。

@squint在their comment中指出,问题是Node.js的过时版本。