1

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

1 Answer 1

1

Use

pugMembers.length <= 6

Your current statement is undefined in terms of behaviour.

Sign up to request clarification or add additional context in comments.

1 Comment

I knew it was something stupid. Works now! Ill give you the answer once 5 mins pass :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.