2

I have this code here:

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

And i want to know how to get the bot to join the kahoot multiple times.

I have already tried adding client.setMaxListeners(Number.POSITIVE_INFINITY) which solves the error with too many listeners. I tried using setInterval() for the join command but it just says Joining kahoot... and never connects.

How would I get the kahootbot to join said kahoot multiple times? (like 100 times or so)

Coll y
  • 83
  • 1
  • 3
  • 11
  • You need one client per player for this library. – jake2389 Sep 15 '19 at 00:49
  • thank you for that answer, I literally got an upvote but no answer lol – Coll y Sep 15 '19 at 00:50
  • 1
    For future reference, it's a lot easier for us if you're using an unofficial library to specify which one you're using in your question. – jake2389 Sep 15 '19 at 00:51
  • could i do something like var num = 0; num++; setInterval(function() { var (client + num) = new Kahoot; }, 30) or something – Coll y Sep 15 '19 at 00:57
  • Mmm well if you want to periodically create them... although you could do a simple for loop and add them to an array if you want a fixed number of players. – jake2389 Sep 15 '19 at 00:59
  • i wanted to know how exactly to make it so that it can make a bunch of clients without me having to put it all the clients myself – Coll y Sep 15 '19 at 01:02
  • Do you need a random number? A fixed number? – jake2389 Sep 15 '19 at 01:03
  • a random number at the end of each client, like client1, client2, etc – Coll y Sep 15 '19 at 01:05
  • 1
    It sounds like you want to dynamically generate variables. [Check this out](https://stackoverflow.com/questions/6645067/javascript-dynamically-creating-variables-for-loops). As that answer suggests, you almost never need to create the actual variables (e.g. client1, client2, etc), because you can use an array. – jake2389 Sep 15 '19 at 01:08
  • for (var i = 0; i <= 400; ++i) { clients[i] = new Kahoot; clients[i].setMaxListeners(10000); clients[i].join(3749 /* Or any other kahoot game pin */, "kahoot.js" + i); } ? – Coll y Sep 15 '19 at 17:18
  • Yeah, that looks like it should work. Perhaps the setMaxListeners might be overkill. – jake2389 Sep 16 '19 at 03:40

1 Answers1

1

Code to join a new bot every 300ms:

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

}

The kahoot client is being created as a local variable in a function, kahoot(), being called every 300ms. This means that a new bot will be created every 300ms. These bots will also answer questions with a random answer.

green726
  • 26
  • 5