Discord Bot 通过 JS 在 twitch 流上线时发出通知

问题描述 投票:0回答:1

我正在尝试创建一个不和谐的机器人,当频道上线时通知人们。我发现了类似的问题和答案,但由于某种原因,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。它们都可以编译,但是当我这样做时!Live 机器人崩溃并给出 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 的新手。

javascript stream bots twitch discord.js
1个回答
0
投票

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

这是不正确的,您没有定义“mybot”

用这个代替:

message.reply("Currently not live");

© www.soinside.com 2019 - 2024. All rights reserved.