-
Notifications
You must be signed in to change notification settings - Fork 0
/
shuffle.js
30 lines (28 loc) · 1.04 KB
/
shuffle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const { MessageEmbed } = require("discord.js");
const sendError = require("../util/error");
module.exports = {
info: {
name: "aleatório",
description: "Toca a lista em uma ordem aleatória",
usage: "[aleatório]",
aliases: ["shuffle", "embaralhar"],
},
run: async function (client, message, args) {
const serverQueue = message.client.queue.get(message.guild.id);
if (!serverQueue) return sendError("A lista está vazia",message.channel).catch(console.error);
try{
let songs = serverQueue.songs;
for (let i = songs.length - 1; i > 1; i--) {
let j = 1 + Math.floor(Math.random() * i);
[songs[i], songs[j]] = [songs[j], songs[i]];
}
serverQueue.songs = songs;
message.client.queue.set(message.guild.id, serverQueue);
message.react("✅")
} catch (error) {
message.guild.me.voice.channel.leave();
message.client.queue.delete(message.guild.id);
return sendError(`:notes: The player has stopped and the queue has been cleared.: \`${error}\``, message.channel);
}
},
};