JavaScript (Node.js) 仅在 Linux Node 上将字符串内容解释为对象

标签 javascript node.js linux string typeerror

我的 Discord.io 机器人出现问题。我试图让它在 Linux 服务器上运行,但是,Linux 版本的 Node.js 不断将字符串的内容解释为单独的对象,导致以下类型错误:

TypeError: 对象 IT'S ALIVE 没有方法 'startsWith' 在 DiscordClient.bot.getMessages.channel (/root/Davixxabots/Daru/Darubot.js:182:17) 在 DiscordClient.emit(events.js:106:17) 在 DiscordClient.handleWSMessage (/root/Davixxabots/Daru/node_modules/discord.io/lib/index.js:1049:11) 在 WebSocket.emit(events.js:98:17) 在 Receiver.ontext (/root/Davixxabots/Daru/node_modules/ws/lib/WebSocket.js:841:10) 在/root/Davixxabots/Daru/node_modules/ws/lib/Receiver.js:536:18 在 Receiver.applyExtensions (/root/Davixxabots/Daru/node_modules/ws/lib/Receiver.js:371:5) 在/root/Davixxabots/Daru/node_modules/ws/lib/Receiver.js:508:14 在 Receiver.flush (/root/Davixxabots/Daru/node_modules/ws/lib/Receiver.js:347:3) 在 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 上运行良好。

在此先感谢您提供的任何帮助!

最佳答案

"...constantly interprets the contents of a string as a seperate object," Don't know what you mean by that, but since your string doesn't have a startsWith() method, seems like you're just using an old version of node.

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

关于JavaScript (Node.js) 仅在 Linux Node 上将字符串内容解释为对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38383703/

相关文章:

javascript - 对 JavaScript 中嵌套函数变量作用域的澄清

javascript - Sleep() 未按预期工作

linux - 并行下载 url 列表并重命名

linux - 从 Windows 访问 Linux Tomcat 端口 8080

linux - bash/linux - touch/mkdir 来自文件中的字符串

javascript - d3 if/else 设置颜色

Javascript 幻灯片褪色问题 - 不无缝

node.js - 由于 imagemin 问题,Grunt 构建失败,出了什么问题?

node.js - 导出CSV文件,并通过浏览器下载,使用express js

node.js - 网络驱动程序错误: cannot find dict 'desiredCapabilities'