Comments (10)
I can't recreate the first issue, playing a song and skipping it ends the queue as it should, playing another song after emits the trackStart once, it might be something on your end.
I don't understand the second thing, 2.3.0 changed how repeating the track and queue works, if you were repeating the track it would always play the same track, now it actually skips the song and repeats the next. If you are able to provide some code to test against it would be very helpful.
from erela.js.
let queue = new Map();
function play(id, serverQueue, message, res) {
try {
const { player, musicClient, loop } = serverQueue;
const embed = createEmbed(message);
// Plays the player (plays the first track in the queue).
// The if statement is needed else it will play the current track again
if (!player.playing && !player.paused && !player.queue.size) player.play();
// bug
// musicClient.on("trackStart", (player, track) => {
// var duration = track.duration / 1000;
// var minutes = Math.floor(duration / 60);
// var seconds = duration - minutes * 60;
// embed
// .setTitle("Now Playing")
// .setDescription(
// ${youtube} [${track.title}](${ // track.uri // }) [${minutes}:${seconds}] - **${track.requester.username}**
// );
// message.channel.send(embed);
// });
// For playlists you'll have to use slightly different if statement
if (
!player.playing &&
!player.paused &&
player.queue.totalSize === res.tracks.length
)
player.play();
musicClient.on("queueEnd", (player) => {
if (loop) {
player.queue.add(player.queue[0]);
} else {
player.destroy();
queue.delete(id);
}
});
} catch (err) {
logger.error(err.stack);
return;
}
}
async function musicHandler(res, message, vc, musicClient) {
try {
const { author, channel, guild } = message;
let serverQueue = queue.get(guild.id);
const embed = createEmbed(message);
if (!serverQueue) {
const player = musicClient.create({
guild: guild.id,
voiceChannel: vc.id,
textChannel: channel.id,
});
const queueConstructor = {
player,
loop: false,
musicClient,
};
player.connect();
// Adds the first track to the queue.
player.queue.add(res.tracks[0]);
queue.set(guild.id, queueConstructor);
// guild.me.voice.setSelfDeaf(true);
play(guild.id, queueConstructor, message, res);
} else {
if (serverQueue.player.voiceChannel !== vc.id) return;
serverQueue.player.queue.add(res.tracks[0]);
}
var duration = res.tracks[0].duration / 1000;
var minutes = Math.floor(duration / 60);
var seconds = duration - minutes * 60;
embed
.setAuthor(author.username, author.displayAvatarURL())
.setDescription(
Queued [${res.tracks[0].title}](${ res.tracks[0].uri }) [**${minutes}:${seconds < 10 ? "0" : ""}${seconds}**] - **${ author.username }**
);
channel.send(embed).catch((err) => {
console.log(err);
logger.error(err.stack);
return;
});
} catch (err) {
console.log(err);
logger.error(err.stack);
return;
}
}
from erela.js.
Here's the code snippet, im not sure why the "trackStart" event is being emitted. Note that this only happens with player.stop()
from erela.js.
const serverQueue = queue.get(guild.id);
const { player } = serverQueue;
if (!serverQueue) {
return channel
.send(":x: There are no songs being played.")
.catch((err) => {
console.log(err);
logger.error(err.stack);
return;
});
}
if (player.voiceChannel !== vc.id) return;
player.stop();
This is my skip/stop func same logic but the stop func has player.destroy()
from erela.js.
For the repeat all im doing is setting the player.setQueueRepeat to true but even when i do this and then skip a song if its the last song in the queue it just ends the queue, but isn't it supposed to repeat the song here? i noticed that if i dont skip or just let the song play until it ends on its own only then it repeats.
from erela.js.
Also, just to make sure, i kinda copied the basic template from the docs which was also resulting in multiple emits
from erela.js.
For the repeat all im doing is setting the player.setQueueRepeat to true but even when i do this and then skip a song if its the last song in the queue it just ends the queue, but isn't it supposed to repeat the song here? i noticed that if i dont skip or just let the song play until it ends on its own only then it repeats.
2.3.0 changed how skipping with repeats on, if you have queue repeat and you skip it'll actually skip the song instead of infinity playing the next songs, if you skip a song you don't want to hear it.
The main issue is have to look later as I just woke up.
from erela.js.
Okay, so i guess all the events are being emitted multiple times, so i guess there's something wrong with my code. i will try to rebuild everything. Thank you for your time!
from erela.js.
Okay, so i found a solution. To recreate what was happening:-
when you instantiate the client.manager = new Manager(options).on("node connection...")
And then if i try to use client.manager.on("trackStart") inside of a client.on("message") It keeps emitting the events multiple times. Its weird though.
The solution was to add the .on(event) at the start before client.on("message")
Its still weird that it emits multiple times when called in a different place.
from erela.js.
Coming back to this, the reason that happens from your last comment is from this:
And then if i try to use client.manager.on("trackStart") inside of a client.on("message") It keeps emitting the events multiple times. Its weird though.
When the message
event is ran you create another trackStart
listener create another each time the message
event is ran, the first time it showed the message Queue ended..
once but after sending another it showed the message twice, will increase every time.
The fix, do not nest events, this will create a memory leak and your bot will crash after reaching the the most it can allocate, which unless there's a limit set (I am not sure about this actually) it will fill all your available memory.
from erela.js.
Related Issues (20)
- Feature Request: ytmsearch
- Weird Queue Problem HOT 4
- defaultSearchPlatform does not work HOT 3
- I donβt understand anything anymore
- Broken with nodejs 18.6 HOT 2
- updateVoiceState on the client issue HOT 2
- Error: Cannot read properties of undefined (reading 'track')
- Unexpected token in JSON at position 0 HOT 2
- Add queue/player events
- Cannot read properties of undefined (reading 'map') : Manager.js:155:36 HOT 1
- Update HOT 6
- Init bug HOT 8
- petitio causing a lot of errors HOT 25
- petitio: unexpected token in json HOT 4
- Plugin Issues HOT 1
- Unexpected token in JSON at position 0 HOT 3
- SyntaxError: Unexpected token in JSON at position 0 on Linux. HOT 1
- Some plugins does not work after latest update HOT 2
- Cannot read properties of undefined (reading 'map'): Manager.js:161:36
- TypeError: finalQuery.match is not a function
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from erela.js.