discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.38k stars 3.97k forks source link

Bot not posting message #368

Closed SloppierKitty7 closed 8 years ago

SloppierKitty7 commented 8 years ago
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

mnlkrs commented 8 years ago
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.

SloppierKitty7 commented 8 years ago

`undefined:1 undefined ^

SyntaxError: Unexpected token u in JSON at position 0 at Object.parse (native) at E:\my ultemet bot\index.js:26:22 at Request._callback (E:\my ultemet bot\node_modules\get-JSON\lib\node.js:11:5) at Request.self.callback (E:\my ultemet bot\node_modules\request\request.js:200:22) at emitTwo (events.js:106:13) at Request.emit (events.js:191:7) at Request. (E:\my ultemet bot\node_modules\request\request.js:1067:10) at emitOne (events.js:101:20) at Request.emit (events.js:188:7) at IncomingMessage. (E:\my ultemet bot\node_modules\request\request.js:988:12)

`

@GexoXYZ doing that now gives this error

SloppierKitty7 commented 8 years ago

@Samutz its https://www.npmjs.com/package/get-json i'm only useing it becous i could not get jquery to work

BrunoMoreira99 commented 8 years ago

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?

SloppierKitty7 commented 8 years ago

@BrunoMoreira991 could you provide a snippet of what it should look like

mnlkrs commented 8 years ago
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");
            }
        });
    }
});
SloppierKitty7 commented 8 years ago

Thanks @GexoXYZ working now

mnlkrs commented 8 years ago

can you close the issue ty