I am designing a jump function for my music bot. When queue.connection.dispatcher.end('skipped') is called once only, it skips a song but when I put it into a loop, it returns an error about UnhandledPromiseRejectionWarning. Can anyone help?
Below is the code for the jump command:
const { MessageEmbed } = require('discord.js');
module.exports = {
name: 'jump',
aliases: [''],
cooldown: 0,
description: '',
async execute(client, message, args, Discord) {
const channel = message.member.voice.channel;
if (!channel)
return message.channel.send("You must be connected to a voice channel"
);
if (!args[0])
return message.channel.send(
new MessageEmbed()
.setDescription(":x: No song number provided")
.setColor("RED")
);
if (isNaN(args[0]))
return message.channel.send(
new MessageEmbed()
.setDescription(":x: **Args must be number [Example: -remove 2]**")
.setColor("RED")
);
let queue = message.client.queue.get(message.guild.id);
if (queue.queue.length == 1)
return message.channel.send(
new MessageEmbed()
.setDescription(
":x: **Can't remove when only one song is playing, Use command stop**"
)
.setColor("RED")
);
if (args[0] > queue.queue.length)
return message.channel.send(
new MessageEmbed()
.setDescription(":x: **The queue doesn't have that much songs**")
.setColor("RED")
);
if (!queue)
return message.channel.send(
new MessageEmbed()
.setDescription(":x: **There are no songs playing in this server**")
.setColor("RED")
);
// var name = queue.queue[args[0] - 1].name;
// queue.queue.splice(args[0] - 1);
for (let i = 0; i < args[0]-1; i++) {
queue.connection.dispatcher.end('skipped');
}
return message.channel.send(new MessageEmbed().setDescription("**Jumped**").setColor("PURPLE"))
}}