discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

24/7 Bot crash #5649

Closed Minecodes closed 3 years ago

Minecodes commented 3 years ago

I coded an 24/7 bot for my AFK channel in Discord and the bot crashes after some restarts of the audio file

Error:

events.js:306
    throw err; // Unhandled 'error' event
    ^

Error [ERR_UNHANDLED_ERROR]: Unhandled error. (ErrorEvent {
  target: WebSocket {
    _events: [Object: null prototype] {
      open: [Function],
      message: [Function],
      close: [Function],
      error: [Function]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    _binaryType: 'nodebuffer',
    _closeCode: 1006,
    _closeFrameReceived: false,
    _closeFrameSent: false,
    _closeMessage: '',
    _closeTimer: null,
    _extensions: {},
    _protocol: '',
    _readyState: 2,
    _receiver: null,
    _sender: null,
    _socket: null,
    _bufferedAmount: 0,
    _isServer: false,
    _redirects: 0,
    _url: 'wss://eu-central4012.discord.media/?v=4&encoding=json',
    _req: null,
    [Symbol(kCapture)]: false
  },
  type: 'error',
  message: 'connect ECONNREFUSED 162.159.138.234:443',
  error: Error: connect ECONNREFUSED 162.159.138.234:443
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
    errno: -111,
    code: 'ECONNREFUSED',
    syscall: 'connect',
    address: '162.159.138.234',
    port: 443
  }
})
    at VoiceConnection.emit (events.js:304:17)
    at VoiceWebSocket.<anonymous> (/home/pi/AFK-Bot/node_modules/discord.js/src/client/voice/VoiceConnection.js:422:32)
    at VoiceWebSocket.emit (events.js:315:20)
    at VoiceWebSocket.onError (/home/pi/AFK-Bot/node_modules/discord.js/src/client/voice/networking/VoiceWebSocket.js:160:10)
    at WebSocket.onError (/home/pi/AFK-Bot/node_modules/ws/lib/event-target.js:140:16)
    at WebSocket.emit (events.js:315:20)
    at ClientRequest.<anonymous> (/home/pi/AFK-Bot/node_modules/ws/lib/websocket.js:579:15)
    at ClientRequest.emit (events.js:315:20)
    at TLSSocket.socketErrorListener (_http_client.js:469:9)
    at TLSSocket.emit (events.js:315:20) {
  code: 'ERR_UNHANDLED_ERROR',
  context: ErrorEvent {
    target: WebSocket {
      _events: [Object: null prototype] {
        open: [Function: onOpen] { _listener: [Function: bound onOpen] },
        message: [Function: onMessage] { _listener: [Function: bound onMessage] },
        close: [Function: onClose] { _listener: [Function: bound onClose] },
        error: [Function: onError] { _listener: [Function: bound onError] }
      },
      _eventsCount: 4,
      _maxListeners: undefined,
      _binaryType: 'nodebuffer',
      _closeCode: 1006,
      _closeFrameReceived: false,
      _closeFrameSent: false,
      _closeMessage: '',
      _closeTimer: null,
      _extensions: {},
      _protocol: '',
      _readyState: 2,
      _receiver: null,
      _sender: null,
      _socket: null,
      _bufferedAmount: 0,
      _isServer: false,
      _redirects: 0,
      _url: 'wss://eu-central4012.discord.media/?v=4&encoding=json',
      _req: null,
      [Symbol(kCapture)]: false
    },
    type: 'error',
    message: 'connect ECONNREFUSED 162.159.138.234:443',
    error: Error: connect ECONNREFUSED 162.159.138.234:443
        at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1146:16) {
      errno: -111,
      code: 'ECONNREFUSED',
      syscall: 'connect',
      address: '162.159.138.234',
      port: 443
    }
  }
}
kyranet commented 3 years ago

Thank you for submitting your bug report, however, you have deleted all the metadata information that came with the template, and as such, it is not easy for us to determine your version of Node.js, OS, and discord.js.

Please edit your issue to include this missing information.


As a side note, did you try the master branch? The bug you're reporting might be fixed already.

amishshah commented 3 years ago

Hi there,

We're working on a new implementation of Discord's Voice API that has better playback quality and is more reliable than what we currently support in Discord.js v12 - check it out at https://github.com/discordjs/voice!

The new library solves many of the issues that users are facing, and as part of this, we're dropping built-in support for voice in our next major release. We have a PR (https://github.com/discordjs/discord.js/pull/5402) that adds native support for our new voice library - once this PR is merged, this issue will be closed.

You can still use our new voice library before that PR lands - just take a look at our music bot example to see how to get started upgrading your voice code. By using the boilerplate music player in the example, you can make it even easier to upgrade your code.

Note that the PR above only reduces some of the boilerplate code you'd otherwise have to write - you do not have to wait for the PR to be merged to start using the new voice library.


If you have any questions about this, feel free to: