Androz2091 / discord-player

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

Queue.playing and Queue.Connection.isPaused always seem to be wrong #1487

Closed royalty37 closed 1 year ago

royalty37 commented 1 year ago

Whenever I attempt to write play and pause commands/subcommands in both a generic manner (such as how the guides/documentation recommend) or more similarly to others who have used discord-player, my player, queue and/or connection objects/instances never seem to behave correctly or hold the correct values.

For example, when I call play, it will play a song, however if I call play while the song is already playing, it will nuke the currently playing song and play the new one... Logging out queue.playing reveals that it is always false, regardless of whether music is playing or not. Furthermore, I can simultaneously log out queue.playing (false) and queue.nowPlaying() (which will return the currently playing song) and get odd results...

Similarly, when I attempt to call pause, it will always say music isn't playing and therefore pause will say something like "Already paused...". I also tried to use queue.connection.paused but this always returns true even when music is playing.

This is my first attempt at creating a Discord bot and admittedly I'm quite stumped.

Any clues why?

LINK TO MY REPO: https://github.com/royalty37/YO-DISCORD-BOT

Additionally, trackStart event is never emitted but I imagine that goes a little deeper (read through some of Discord-Player, Discord.JS but too much trouble).

To Reproduce Steps to reproduce the behavior:

  1. install and run project
  2. Attempt to use /music play or /music pause

Expected behavior They work correctly!!!!

Kief5555 commented 1 year ago

I'm having the same issue.

Kief5555 commented 1 year ago

@Androz2091 Are you able to reproduce this?

Kief5555 commented 1 year ago

Ah. I tried version 5.3.2. Seems like that does not have the issue. Cheers!

XCOYoshi commented 1 year ago

same with my implementation in version 5.4.0 repo: https://github.com/SJ-Plan-B/Plan-Bot

Kief5555 commented 1 year ago

same with my implementation in version 5.4.0

repo: https://github.com/SJ-Plan-B/Plan-Bot

Just use 5.3.2

royalty37 commented 1 year ago

same with my implementation in version 5.4.0 repo: https://github.com/SJ-Plan-B/Plan-Bot

Just use 5.3.2

As mentioned in my original post, I'm having this issue with 5.3.1. Any ideas?

Kief5555 commented 1 year ago

same with my implementation in version 5.4.0

repo: https://github.com/SJ-Plan-B/Plan-Bot

Just use 5.3.2

As mentioned in my original post, I'm having this issue with 5.3.1. Any ideas?

Try to update .1 version? Lol. It works for me, returns true when isPlaying.

to update you can do npm i discord-player@5.3.2

twlite commented 1 year ago

I've been trying to reproduce this bug. In my case, this seems to be happening randomly.

Kief5555 commented 1 year ago

I've been trying to reproduce this bug. In my case, this seems to be happening randomly.

It happens every time for me. I'm not sure which version the standard npm i discord-player does but that was causing the issue, so I downgraded

twlite commented 1 year ago

Sometimes connection.paused somehow seems to be true without setting it although it is initialized as false. I will change the connection.paused property to a getter returning audioPlayer.state.status === AudioPlayerStatus.Paused instead which should hopefully fix this issue as it returns what audioPlayer holds.

twlite commented 1 year ago

I've opened a PR against this issue #1517

twlite commented 1 year ago

After testing this for a while, I haven't faced this issue yet. This fix seems to be working but needs more tests. I could publish this version on @dev tag but the codebase is currently using extractors v4 dev version which may not be stable currently.

XCOYoshi commented 1 year ago

I've been trying to reproduce this bug. In my case, this seems to be happening randomly.

it is pretty randomly but it happens way more often after restart if the script it is 2 about if 3 times

XCOYoshi commented 1 year ago

same with my implementation in version 5.4.0 repo: https://github.com/SJ-Plan-B/Plan-Bot

Just use 5.3.2

still persistent in 5.3.2

twlite commented 1 year ago

Fix for this https://github.com/Androz2091/discord-player/pull/1517 has been merged into dev branch. The fix will be out on stable once #1513 is merged into master.

twlite commented 1 year ago

Hello, those who are having issues, could you try using npm i discord-player@dev and see if this problem still persists?

XCOYoshi commented 1 year ago

on it

XCOYoshi commented 1 year ago

Hello, those who are having issues, could you try using npm i discord-player@dev and see if this problem still persists?

is it possible that the equalizer is not part of the dev branches because I am getting this error:

TypeError: import_equalizer.AudioFilter is not a constructor
    at StreamDispatcher.createStream (I:\GIT\Plan-Bot\node_modules\discord-player\dist\index.js:1614:27)
    at Queue.play (I:\GIT\Plan-Bot\node_modules\discord-player\dist\index.js:1401:38)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.execute (I:\GIT\Plan-Bot\commands\play.js:68:25)
    at async Client.<anonymous> (I:\GIT\Plan-Bot\index.js:91:90)
twlite commented 1 year ago

Hello, those who are having issues, could you try using npm i discord-player@dev and see if this problem still persists?

is it possible that the equalizer is not part of the dev branches because I am getting this error:

TypeError: import_equalizer.AudioFilter is not a constructor
    at StreamDispatcher.createStream (I:\GIT\Plan-Bot\node_modules\discord-player\dist\index.js:1614:27)
    at Queue.play (I:\GIT\Plan-Bot\node_modules\discord-player\dist\index.js:1401:38)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.execute (I:\GIT\Plan-Bot\commands\play.js:68:25)
    at async Client.<anonymous> (I:\GIT\Plan-Bot\index.js:91:90)

🤔 does npm i @discord-player/equalizer@latest fix the problem?

XCOYoshi commented 1 year ago

that fixes it THX

XCOYoshi commented 1 year ago

the bug is gone to

twlite commented 1 year ago

Starting with discord-player@dev, you don't need onBeforeCreateStream to use play-dl. Discord Player will automatically prefer play-dl over ytdl-core when it can detect play-dl.

royalty37 commented 1 year ago

possible that the equalizer is not part of the dev branches because I am getting this error:

I'm having a new issue after using the @dev version.

Now calling play will cause Queue to to throw a write EPIPE erorr...?

twlite commented 1 year ago

possible that the equalizer is not part of the dev branches because I am getting this error:

I'm having a new issue after using the @dev version.

Now calling play will cause Queue to to throw a write EPIPE erorr...?

Could you tell me the versions of these libs:

Additionally, try installing play-dl

royalty37 commented 1 year ago
image

Don't think I had either installed when I first tested but installing doesn't seem to make a difference...

Here is my play command:

export const handlePlaySubcommand = async (interaction: ChatInputCommandInteraction) => {
  // Get client off of interaction
  const client: YoClient = interaction.client as YoClient;

  await interaction.deferReply();

  const guild = client.guilds.cache.get(interaction.guildId ?? "");
  const channel = guild?.channels.cache.get(interaction.channelId ?? "");
  const song = interaction.options.getString(SONG_OPTION_NAME, INPUT_REQUIRED);

  if (!guild || !channel) {
    return void interaction.followUp({ content: "There was an error while executing this command!" });
  }

  // Search for song and get search result
  const searchResult = await client.player
    .search(song, {
      requestedBy: interaction.user,
      searchEngine: QueryType.AUTO,
    })
    .catch(() => {
      console.error("*** Exception in Play Subcommand - Player.search***");
    });

  if (!searchResult || !searchResult.tracks.length) {
    return void interaction.followUp("No results were found!");
  }

  // Create a queue for the guild if one doesn't exist
  const queue = client.player.createQueue(guild, {
    ytdlOptions: {
      filter: "audioonly",
      highWaterMark: 1 << 30,
      dlChunkSize: 0,
    },
    metadata: channel,
  });

  const member = guild.members.cache.get(interaction.user.id) ?? (await guild.members.fetch(interaction.user.id));

  if (!member.voice.channel) {
    return void interaction.followUp("You must be in a voice channel!");
  }

  if (!interaction.guildId) {
    return void interaction.followUp("There was an error while executing this command!");
  }

  // Connect to the voice channel and add the track to the queue
  // If exception is thrown, delete the queue and return
  try {
    if (!queue.connection) {
      await queue.connect(member.voice.channel);
    }
  } catch {
    client.player.deleteQueue(interaction.guildId);
    return void interaction.followUp("Could not join your voice channel!");
  }

  // Add track to queue and play if not already playing
  await interaction.followUp(`⏱ | Loading your ${searchResult.playlist ? "playlist" : "track"}...`);
  searchResult.playlist ? queue.addTracks(searchResult.tracks) : queue.addTrack(searchResult.tracks[0]);

  // If the queue is not playing, play it
  if (!queue.playing) {
    await queue.play();
  }

  // If the queue is paused, unpause it
  if (queue.setPaused(false)) {
    interaction.followUp("▶ | Queued song - Resumed!");
  }
};

Gets all the way to the bottom but then throws EPIPE issue shortly after calling play, bot joins voice channel but plays nothing...

Danrejk commented 1 year ago

Hello, those who are having issues, could you try using npm i discord-player@dev and see if this problem still persists?

I am unable to check. When on the @dev version, the QueryType seems to be not working for me. It simply returns me: https://pastebin.com/8wWAjyBk Instead of https://pastebin.com/KMRxa2BA, as it does in the 5.4.0 version

twlite commented 1 year ago

Hello, those who are having issues, could you try using npm i discord-player@dev and see if this problem still persists?

I am unable to check. When on the @dev version, the QueryType seems to be not working for me. It simply returns me: https://pastebin.com/8wWAjyBk Instead of https://pastebin.com/KMRxa2BA, as it does in the 5.4.0 version

in dev version, player.search returns a SearchResult object instead of plain object. The search result object contains og playlist and tracks getters so it should be compatible with existing codebases

twlite commented 1 year ago

However, the codebases that used direct values instead of QueryType will break as some changes were made to QueryType enum.

twlite commented 1 year ago

Hello, those who are having issues, could you try using npm i discord-player@dev and see if this problem still persists?

I am unable to check. When on the @dev version, the QueryType seems to be not working for me. It simply returns me: https://pastebin.com/8wWAjyBk Instead of https://pastebin.com/KMRxa2BA, as it does in the 5.4.0 version

what I can see from your SearchResult object is you don't have extractors available. Unline before, discord-player no longer provides built-in extractors, everything has been moved to @discord-player/extractor package. Discord Player should install that automatically but if not then there is likely a problem of some dependencies.

Could you try running these?

npm i play-dl npm i @discord-player/extractor@latest

Danrejk commented 1 year ago

Thanks for taking a look at it. Both are up to date, and the SearchResult output is the same.

This is my code that I used for checking that. Maybe it is the issue:

const result = await client.player.search(url, {
    requestedBy: interaction.user,
    searchEngine: QueryType.YOUTUBE_VIDEO
})
console.log(result)
Danrejk commented 1 year ago

Running npm i node-fetch some time ago seemed to be the issue. The @dev version works now. Sorry for the troubles.