【问题标题】:How do i get the kahootbot to join multiple times?我如何让 kahootbot 多次加入?
【发布时间】:2020-01-16 07:17:41
【问题描述】:

我这里有这段代码:

var Kahoot = require("kahoot.js-updated");
var client = new Kahoot;
console.log("Joining kahoot...");
client.join(9802345 /* Or any other kahoot game pin */, "kahoot.js");
client.on("joined", () => {
    console.log("I joined the Kahoot!");
});
client.on("quizStart", quiz => {
    console.log("The quiz has started! The quiz's name is:", quiz.name);
});
client.on("questionStart", question => {
    console.log("A new question has started, answering the first answer.");
    question.answer(0);
});
client.on("quizEnd", () => {
    console.log("The quiz has ended.");
});

我想知道如何让机器人多次加入 kahoot。

我已经尝试添加client.setMaxListeners(Number.POSITIVE_INFINITY),它解决了太多听众的错误。我尝试使用setInterval() 对于 join 命令,但它只是说 Joining kahoot... 并且从不连接。

如何让 kahootbot 多次加入所说的 kahoot? (大概100次左右)

【问题讨论】:

  • 对于这个库,每个播放器需要一个客户端。
  • 谢谢你的回答,我确实得到了一个赞成票,但没有回答大声笑
  • 为了将来参考,如果您使用非官方库来指定您在问题中使用的库,这对我们来说会容易得多。
  • 我可以做类似 var num = 0; 的事情吗?数++; setInterval(function() { var (client + num) = new Kahoot; }, 30) 什么的
  • 听起来你想动态生成变量。 Check this out。正如该答案所暗示的那样,您几乎不需要创建实际变量(例如 client1、client2 等),因为您可以使用数组。

标签: javascript node.js package node-modules


【解决方案1】:

每 300 毫秒加入一个新机器人的代码:

const Kahoot = require("kahoot.js-updated");


setInterval(kahoot, 300)
function kahoot() {
const client = new Kahoot;
var name = Math.floor(Math.random() * 99999999).toString()

client.join(2676002, name);

client.on("Joined", () => {
  console.log("I joined the Kahoot!");
}); 

client.on("QuizStart", () => {
}); 

client.on("QuestionStart", question => {
  question.answer(Math.floor(Math.random() * 5));
  console.log('i answered a question') 
});
client.on("QuizEnd", () => {
  console.log("The quiz has ended.");
}); 

}

kahoot 客户端被创建为函数 kahoot() 中的局部变量,每 300 毫秒调用一次。这意味着将每 300 毫秒创建一个新机器人。这些机器人也会随机回答问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-17
    • 1970-01-01
    • 2018-07-21
    相关资源
    最近更新 更多