gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:03 25 4
gpt4 key购买 nike

我的 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com