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

JavaScript (Node.js) interprets String contents as an Object on Linux Node only

本文关键字:Linux 解释 节点 对象 js Node 字符串 JavaScript      更新时间:2023-09-26

我的 Discord.io 机器人有问题。我试图让它在 Linux 服务器上运行,但是,Linux 版本的 Node.js 不断将字符串的内容解释为单独的对象,导致以下 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上运行良好。

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

"...不断将字符串的内容解释为一个单独的对象,"不知道你的意思,但由于你的字符串没有 startsWith() 方法,看起来你只是在使用旧版本的 node。

正如@squint在他们的评论中指出的那样,这个问题是Node.js的过时版本。