Discord Bot通过JS

时间:2017-06-06 12:33:55

标签: javascript stream bots twitch discord.js

我正在尝试创建一个不和谐的机器人,在频道上线时通知人们。我找到了类似的问题和答案,但由于某种原因,jquery似乎不起作用,我需要使用getJSON。

这是我的index.js文件。

const Discord = require('discord.js');

const commando = require('discord.js-commando');
const bot = new commando.Client();

const BotToken = "bottoken";
const TwitchClientID = "twitchclientID";
const TwitchURL = "https://api.twitch.tv/kraken/streams/channelname";
const channelName = "channelname";

bot.registry.registerGroup('random', 'Random');
bot.registry.registerDefaults
bot.registry.registerCommandsIn(__dirname + "/commands");

bot.login('login'); 

bot.on("message", function(message) {
    if (message.content === "!Live") {
        getJSON("https://api.twitch.tv/kraken/streams/channelname", function(err, res) {
            if (res.stream == null) {
                mybot.reply(message, "currently not live");
            } else {
                mybot.reply(message, "currently live");
            }
        });
    }
});

我也尝试了jQuery.getJSON和$ .getJSON。他们都编译但是当我这样做!实施机器人崩溃并且没有定义getJSON。

这是我的package.json文件。

{
  "name": "name",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^11.1.0",
    "discord.js-commando": "^0.9.0",
    "jquery": "^3.2.1",
    "xmlhttprequest": "^1.8.0"
  }
}

我不确定为什么我不能让getJSON工作,因为这个解决方案应该有效。感谢任何帮助,如果这看起来像是一个愚蠢的问题,我很抱歉,我是js的新手并使用其他API。

1 个答案:

答案 0 :(得分:1)

mybot.reply(message, "currently not live");

这是不正确的,你没有定义mybot'

请改用:

message.reply("Currently not live");