mybot.on("message", function(message) {
if(message.content === "!Live") {
getJSON("https://api.twitch.tv/kraken/streams/Jonathan_x64?callback=?", function(c) {
if (c.stream == null) {
//ofline
mybot.reply(message, "she is currently not live");
} else {
//online
mybot.reply(message, "she is currently live");
}
}),
}
});
also wont long anything in the console when using console.log
mybot.on("message", function(message) {
if (message.content === "!Live") {
getJSON("https://api.twitch.tv/kraken/streams/Jonathan_x64", function(c) {
c = JSON.parse(c);
if (c.stream == null) {
mybot.reply(message, "she is currently not live");
} else {
mybot.reply(message, "she is currently live");
}
});
}
});
You can't use the callback like that, try to follow the twitch link.
Also I don't know if getJSON does this automatically for you but you need to parse it into an actual json object.
`undefined:1
undefined
^
SyntaxError: Unexpected token u in JSON at position 0
at Object.parse (native)
at E:my ultemet botindex.js:26:22
at Request._callback (E:my ultemet botnode_modulesget-JSONlibnode.js:11:5)
at Request.self.callback (E:my ultemet botnode_modulesrequestrequest.js:200:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.
at emitOne (events.js:101:20)
at Request.emit (events.js:188:7)
at IncomingMessage.
`
@GexoXYZ doing that now gives this error
@Samutz its https://www.npmjs.com/package/get-json i'm only useing it becous i could not get jquery to work
You're using it wrong, your c is the error, use something like function(error, response) instead.
But I'm not sure about the json now, would be response.result.stream maybe?
@BrunoMoreira991 could you provide a snippet of what it should look like
mybot.on("message", function(message) {
if (message.content === "!Live") {
getJSON("https://api.twitch.tv/kraken/streams/Jonathan_x64", function(err, res) {
if (res.stream == null) {
mybot.reply(message, "she is currently not live");
} else {
mybot.reply(message, "she is currently live");
}
});
}
});
Thanks @GexoXYZ working now
can you close the issue ty
Most helpful comment