Androz2091 / discord-player

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

ECONNRESET #1895

Closed luigimqf closed 6 months ago

luigimqf commented 6 months ago

Issue description

I'm using discord.js along with discord-player to play music. Other commands are working just fine, but when I use the play command and add music to the queue, the bot stops playing after 40-60 seconds and throws the error below. I tried reviewing the libs' dependencies and even recreating the bot, but nothing seems to work. I ran out of ideas on how to fix this issue.

Error ```js node:events:496 throw er; // Unhandled 'error' event ^ Error: read ECONNRESET at TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) Emitted 'error' event on BodyReadable instance at: at emitErrorNT (node:internal/streams/destroy:169:8) at emitErrorCloseNT (node:internal/streams/destroy:128:3) at process.processTicksAndRejections (node:internal/process/task_queues:82:21) { errno: -4077, code: 'ECONNRESET', syscall: 'read' } ```
Play Command ```js const { useMainPlayer } = require("discord-player"); const { EmbedBuilder, Application, ApplicationCommandOptionType, } = require("discord.js"); const data = { name: "play", description: "Play a song", options: [ { name: "url", description: "Nome ou Link da música", type: ApplicationCommandOptionType.String, required: true, }, ], }; async function run({ interaction, client }) { const player = useMainPlayer(client); const channel = interaction.member.voice.channel; if (!channel) return interaction.reply("Você não está em um canal de voz!"); const query = interaction.options.getString("url", true); const embed = new EmbedBuilder() .setAuthor({ name: "Carregando música..." }) .setColor("#8e44ad"); const reply = await interaction.reply({ embeds: [embed] }); try { const { track } = await player.play(channel, query, { requestedBy: interaction.user, }); if (track.playlist) { embed .setAuthor({ name: `Playlist adicionado á queue`, iconURL: client.user.displayAvatarURL(), }) .setDescription( `▶️ Adicionado à queue: **${track.playlist.tracks.length} músicas** ` ) .setTimestamp() .toJSON(); embed .setAuthor({ name: `Música adicionada à queue!`, iconURL: client.user.displayAvatarURL(), }) .setThumbnail(track.thumbnail) .setDescription(`▶️ Adicionado à queue: **${track.title}** `) .setFooter({ text: `Comando executado por ${interaction.user.tag}`, iconURL: interaction.user.displayAvatarURL(), }) .setTimestamp() .toJSON(); await reply.edit({ embeds: [embed] }); return; } } catch (error) { embed .setAuthor({ name: `Erro ao tocar a música!`, iconURL: client.user.displayAvatarURL(), }) .setDescription(`❌ Ocorreu um erro ao tocar a música!`) .setFooter({ text: `Comando executado por ${interaction.user.tag}`, iconURL: interaction.user.displayAvatarURL(), }) .setTimestamp() .toJSON(); await reply.edit({ embeds: [embed] }); return; } } module.exports = { data, run }; ```
package.json ```js { "name": "", "version": "1.0.0", "main": "index.js", "scripts": { "start": "nodemon ./src/main.js", "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "description": "", "dependencies": { "@discord-player/extractor": "^4.4.7", "@discordjs/voice": "^0.16.1", "commandkit": "^0.1.10", "discord-player": "^6.6.8", "discord.js": "^14.14.1", "dotenv": "^16.4.5", "ffmpeg-static": "^5.2.0", "genius-lyrics": "^4.4.7", "mediaplex": "^0.0.9", "youtube-ext": "^1.1.23" } } ```
main.js ```js const {Client, GatewayIntentBits} = require('discord.js'); const {CommandKit} = require('commandkit'); const path = require('path'); const dotenv = require('dotenv'); const {Player} = require('discord-player'); dotenv.config(); const {Token: TOKEN} = process.env; const client = new Client({ intents: [ GatewayIntentBits.Guilds, GatewayIntentBits.GuildVoiceStates ] }); client.config = require('./config'); const player = new Player(client, client.config.opt.discordPlayer); player.extractors.loadDefault(); new CommandKit({ client, commandsPath: path.join(__dirname, 'commands'), eventsPath: path.join(__dirname, 'events'), }); client.login(TOKEN); ```

I read some articles about this and its seems unlikely that the error occurs on discord-player side

Versions

Issue priority

Medium (should be fixed soon)

Which gateway intents are you subscribing to?

Guilds, GuildVoiceStates

GlitchApotamus commented 6 months ago

Can you try hosting the bot with another internet provider? You might be getting disconnected due to packet loss or something similar.

luigimqf commented 6 months ago

Can you try hosting the bot with another internet provider? You might be getting disconnected due to packet loss or something similar.

@needhamgary My friend from another state is helping me with this bot and he's having tha same problem with a different description:

node:events:492
      throw er; // Unhandled 'error' event
      ^

SocketError: other side closed
    at TLSSocket.onSocketEnd (/opt/SpaceFunk/node_modules/undici/lib/client.js:1129:22)
    at TLSSocket.emit (node:events:526:35)
    at endReadableNT (node:internal/streams/readable:1408:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on BodyReadable instance at:
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  code: 'UND_ERR_SOCKET',
  socket: {
    localAddress: '192.168.140.102',
    localPort: 35188,
    remoteAddress: undefined,
    remotePort: undefined,
    remoteFamily: undefined,
    timeout: undefined,
    bytesWritten: 1232,
    bytesRead: 1016310
  }
}

This error seems to indicate that the connection to the socket has been closed from the other end. Could be because of network issues, time limits, or even specific problems with the library to play music on Discord.

twlite commented 6 months ago

Hello @luigimqf, this is a known issue of youtube-ext which is caused by the lib not implementing retry logic during streaming process. This issue occurs when ffmpeg is not in use. Discord Player by default tries to not spawn ffmpeg at all when it is not required in order to save resources.

You can follow one of these steps to resolve this issue:

cc @zyrouge

luigimqf commented 6 months ago

@twlite This worked perfectly for me, thanks. I was almost certain that the error was linked to the player because the other commands were working just fine.