Giter VIP home page Giter VIP logo

Comments (10)

Solaris9 avatar Solaris9 commented on August 20, 2024

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.

HoaX7 avatar HoaX7 commented on August 20, 2024

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.

HoaX7 avatar HoaX7 commented on August 20, 2024

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.

HoaX7 avatar HoaX7 commented on August 20, 2024
  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.

HoaX7 avatar HoaX7 commented on August 20, 2024

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.

HoaX7 avatar HoaX7 commented on August 20, 2024

Also, just to make sure, i kinda copied the basic template from the docs which was also resulting in multiple emits

from erela.js.

Solaris9 avatar Solaris9 commented on August 20, 2024

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.

HoaX7 avatar HoaX7 commented on August 20, 2024

bug
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.

HoaX7 avatar HoaX7 commented on August 20, 2024

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.

Solaris9 avatar Solaris9 commented on August 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.