I am sure the solution to my problem is something easy that I am overlooking.
What I am trying to do is when a user types !add in discord, the bot will add them into an array (for a 6 man pick up game).
Currently when the first user types !add, it adds them to the array. When the second user does !add, the array does not add the second user and keeps the first user in the array.
The way it should work is user 1 and user 2 are both in the array.
const pugSize = 6; // Maximum amount of players in the PUG
const pugMembers = []; // Array to hold the members in the PUG
function checkPugSize(){
if (pugMembers.length == 6){
//TODO Create the two teams
console.log(`PUG IS FULL: ${pugMembers.length}`);
}else{
console.log(`THE PUG IS NOT FULL: ${pugMembers.length}`);
}
}
function addUserPug(msg){
// console.log(msg.author);
// Add user to the pugMembers Array if the array is not full
if (pugMembers<=6){
pugMembers.push(msg.author.username);
}else{ // Create a new pug and pass the user into the array
console.log("TODO: Create a new pug when current array is filled");
// createNewPug(msg.author.username);
}
msg.channel.send(`${msg.author} added to queue ${pugMembers.length}/6.`); // Mention the user that they are added into the queue
// msg.reply(' added to queue. ' + `${pugMembers.length}/6`);
msg.delete()
.then(msg => console.log(pugMembers))
.catch(console.error);
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', msg => {
if (msg.content == '!size'){
msg.channel.send(`Current PUG size: ${pugMembers.length}`);
}
if (msg.content === '!add'){
// console.log(msg.author);
checkPugSize();
addUserPug(msg);
}
});