Discord.js: Bot not posting message

Created on 23 May 2016  路  8Comments  路  Source: discordjs/discord.js

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

question (please use Discord instead)

Most helpful comment

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");
            }
        });
    }
});

All 8 comments

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. (E:my ultemet botnode_modulesrequestrequest.js:1067:10)
at emitOne (events.js:101:20)
at Request.emit (events.js:188:7)
at IncomingMessage. (E:my ultemet botnode_modulesrequestrequest.js:988:12)

`

@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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DreamXZE picture DreamXZE  路  39Comments

PaulSenon picture PaulSenon  路  19Comments

vladfrangu picture vladfrangu  路  23Comments

MattIPv4 picture MattIPv4  路  18Comments

tandpfun picture tandpfun  路  27Comments