forked from embee/woomy
shuffle command now excluses the first element
This commit is contained in:
parent
6d5d476528
commit
4d97bc1ad0
1 changed files with 7 additions and 9 deletions
|
@ -25,15 +25,13 @@ module.exports.run = (client, message, args, level) => {
|
|||
return message.channel.send('Not enough songs are in the queue for this command to work!')
|
||||
}
|
||||
|
||||
let j, x, i
|
||||
|
||||
// Make it so it shuffles all elements EXCEPT [0]
|
||||
|
||||
for (i = queue.length - 1; i > 1; i--) {
|
||||
j = Math.floor(Math.random() * (i + 1))
|
||||
x = queue[i]
|
||||
queue[i] = queue[j]
|
||||
queue[j] = x
|
||||
const max = queue.length - 1
|
||||
const min = 1
|
||||
for (let i = max; i >= min; i--) {
|
||||
const randomIndex = Math.floor(Math.random() * (max - min + 1)) + min
|
||||
const itemAtIndex = queue[randomIndex]
|
||||
queue[randomIndex] = queue[i]
|
||||
queue[i] = itemAtIndex
|
||||
}
|
||||
|
||||
message.channel.send('Queue shuffled!')
|
||||
|
|
Loading…
Reference in a new issue