Skip to content

Commit

Permalink
refactor: refactor for shorter code
Browse files Browse the repository at this point in the history
  • Loading branch information
eritislami committed Nov 6, 2020
1 parent 161d07a commit efb7488
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions commands/skipto.js
Expand Up @@ -5,31 +5,27 @@ module.exports = {
aliases: ["st"],
description: "Skip to the selected queue number",
execute(message, args) {
if (!args.length)
return message
.reply(`Usage: ${message.client.prefix}${module.exports.name} <Queue Number>`)
.catch(console.error);

if (isNaN(args[0]))
if (!args.length || isNaN(args[0]))
return message
.reply(`Usage: ${message.client.prefix}${module.exports.name} <Queue Number>`)
.catch(console.error);

const queue = message.client.queue.get(message.guild.id);
if (!queue) return message.channel.send("There is no queue.").catch(console.error);
if (!canModifyQueue(message.member)) return;

if (args[0] > queue.songs.length)
return message.reply(`The queue is only ${queue.songs.length} songs long!`).catch(console.error);

queue.playing = true;

if (queue.loop) {
for (let i = 0; i < args[0] - 2; i++) {
queue.songs.push(queue.songs.shift());
}
} else {
queue.songs = queue.songs.slice(args[0] - 2);
}

queue.connection.dispatcher.end();
queue.textChannel.send(`${message.author} ⏭ skipped ${args[0] - 1} songs`).catch(console.error);
}
Expand Down

0 comments on commit efb7488

Please sign in to comment.