Skip to content
This repository has been archived by the owner on Nov 13, 2022. It is now read-only.

queue.remove() not working as intended? #76

Closed
pab14567 opened this issue Jan 3, 2021 · 6 comments
Closed

queue.remove() not working as intended? #76

pab14567 opened this issue Jan 3, 2021 · 6 comments

Comments

@pab14567
Copy link

pab14567 commented Jan 3, 2021

Hi! I'm not sure If I'm reading it wrong or using it improperly, but I'm trying to let the users choose what track to remove from the queue and no matter what number the user replies with, it only removes the next track after the current one playing. It does not remove the specified track.

player.queue.remove(args[0])

is what I'm using, if you need more let me know!

Any ideas? (Using up to date version of erela.js)

@t3ned
Copy link

t3ned commented Jan 3, 2021

The queue#remove method is working perfectly. Note the current playing track is not included when removing tracks from the queue (written in CAPS in the documentation). Queue index starts at 0. Hope this helps!

@pab14567
Copy link
Author

pab14567 commented Jan 3, 2021

Yeah!
args[0] is whatever the user inputs and i've been putting higher than 0 and there's 12 songs on the queue. I'm trying to remove the 6th song in the queue, but no matter what number i put into the remove() method, it only removes the first track on the queue.

@Solaris9
Copy link
Contributor

Solaris9 commented Jan 3, 2021

Doing some tests it seems like providing undefined which you are most likely doing will remove only the first element in the array, this is because JavaScript treats all falsy values as the number 0 literally. You will probably say you're not giving undefined but JavaScript doesn't care what you do if you try to access a undefined (no value defined) value, this includes array elements and properties. You should check what the user is providing beforehand, if it exists, if it's a number, if it's in range of the queue, if all of those don't fail then remove it from the queue. Another good solution for long time would be to use TypeScript as it will catch basically all these errors and hint towards better code.

@burnthoney
Copy link

burnthoney commented Jan 3, 2021

I would like to point out that args[0] is probably a string. Try convert it before you remove it. Something like this

const index = Number(args[0]) || 0
player.queue.remove(index)
Note that the the || was added incase it failed to convert

@pab14567
Copy link
Author

pab14567 commented Jan 3, 2021

I actually just realized my mistake, I'm an idiot.

I wasn't getting the track correctly, and it was returning the first track in the queue, rather than the track I was removing.

Thanks for the help! Sorry for the bother

@pab14567 pab14567 closed this as completed Jan 3, 2021
@Solaris9
Copy link
Contributor

Solaris9 commented Jan 3, 2021

I would like to point out that args[0] is probably a string. Try convert it before you remove it. Something like this

const index = Number(args[0]) || 0
player.queue.remove(index)
Note that the the || was added incase it failed to convert

It being a number does not matter with JavaScript, however I will be adding more strict types so this won't be an issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants