Androz2091 / discord-player

🎧 Complete framework to simplify the implementation of music commands using discord.js v14
https://discord-player.js.org/
MIT License
589 stars 192 forks source link

playerPause and playerResume events emitted when bot disconnect #1897

Closed Drilmo closed 1 month ago

Drilmo commented 4 months ago

Describe the bug When the bot is alone in the channel, it disconnects from the voice channel and emit the playerPause and playerResume events when it shouldn't.

To Reproduce Steps to reproduce the behavior: configure the bot to leave the lounge if it's alone (leaveOnEmpty: true) go to a vocal channel. call the bot play music leave the lounge

Expected behavior playerPause and playerResume events must not be emitted

Please complete the following information:

twlite commented 4 months ago

@Drilmo discord-player indeed pauses the playback when bot is alone in a voice channel, which is most likely the reason for these events to get triggered. Though pause event kind of makes sense here, it does not make sense for resume event to get emitted. Therefore, this is indeed a bug.

Do you see this behavior with pauseOnEmpty: false option? By default this is set to true. Disabling this option should never trigger these events (unless these actions are manually called).

Drilmo commented 4 months ago

@Drilmo discord-player indeed pauses the playback when bot is alone in a voice channel, which is most likely the reason for these events to get triggered. Though pause event kind of makes sense here, it does not make sense for resume event to get emitted. Therefore, this is indeed a bug.

Do you see this behavior with pauseOnEmpty: false option? By default this is set to true. Disabling this option should never trigger these events (unless these actions are manually called).

I have the same behavior with this configuration:

nodeOptions: {
          metadata: {
            interaction,
            volume: 100,
            leaveOnEnd: false,
            leaveOnStop: true,
            leaveOnEmpty: true,
            selfDeaf: true,
            pauseOnEmpty: false,
          },
        },

playerPause and playerResume events are emitted

twlite commented 4 months ago

@Drilmo discord-player indeed pauses the playback when bot is alone in a voice channel, which is most likely the reason for these events to get triggered. Though pause event kind of makes sense here, it does not make sense for resume event to get emitted. Therefore, this is indeed a bug. Do you see this behavior with pauseOnEmpty: false option? By default this is set to true. Disabling this option should never trigger these events (unless these actions are manually called).

I have the same behavior with this configuration:

nodeOptions: {
          metadata: {
            interaction,
            volume: 100,
            leaveOnEnd: false,
            leaveOnStop: true,
            leaveOnEmpty: true,
            selfDeaf: true,
            pauseOnEmpty: false,
          },
        },

hi, everything except interaction goes outside metadata object.

Let me clarify this, metadata object allows you to store raw information that you may need later on. In this case, you require interaction object to identify where to send messages when discord-player emits an event on a queue. This object can be accessed via queue.metadata when consuming.

Options such as volume, leaveOnEnd, etc. go outside metadata as these are options for the queue itself. A guild queue does not read options from metadata. In fact, discord-player never actually reads your metadata internally. Correct way of doing this would be

nodeOptions: {
  metadata: {
    interaction,
  },
  volume: 100,
  leaveOnEnd: false,
  leaveOnStop: true,
  leaveOnEmpty: true,
  selfDeaf: true,
  pauseOnEmpty: false,
},
Drilmo commented 4 months ago

Ho! thank you for this explanation indeed it's a mistake on my part! I followed a tutorial on YouTube for the initialization... Thank you very much for your time...

Drilmo commented 4 months ago

@twlite I tried again with pauseOnEmpty: false it works as expected. However, out of curiosity, I tested with pauseOnEmpty: true, and the playerResume event was triggered after the playerPause event.