client.on('voiceStateUpdate', (oldState, newState) => { // Queue channel let mainChannel = '880955614442954752'; let testingChannel = '889287515301883904'; // If the channel the user is in is equal to the queue channel... if (newState.channelId === mainChannel || newState.channelId === testingChannel) { let memberID = newState.member.id; if (!test.includes(memberID)) { // Add to the test array console.log(memberID + " joined the queue VC."); con.query(`SELECT * FROM rbridge WHERE id = '${newState.member.id}'`, (err, rows) => { if (err) throw err; let userElo = rows[0].elo; test.push([memberID, userElo, 0]); console.log(test[0]); }) } else { console.log(memberID + " was already in the array."); } // If there is more then one person in the VC... if (test.length > 1) { test.sort(function(a, b) { console.log(a[1] - b[1]); }) } } else { var user = test[0]; if (newState.member.id === user) { test.shift(); } } });