Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.71k stars 3.74k forks source link

What is happening with voice #1110

Closed Zenrac closed 6 years ago

Zenrac commented 6 years ago

I merged my bot to the rewrite ver of discord.py and I got some weird issues with voice. My problem is that the bot is connected to a voice channel without being really connected.

I'm really lost and I've no idea how it can happens. I don't have any ways to show you any tracebacks or how to repro.

But I used an "eval command" to show you a weird point I found :

capture

As you can see, there is a channel attribute but .is_connected() returns False. I tried to force the bot to disconnect itself in vain. Any ideas ? How it can be possible ?

PS : The bot cannot moves to another channel and it is not showed as connected on the discord interface.

jusplainmike commented 6 years ago

I don't believe voice support is working in rewrite.

https://discordpy.readthedocs.io/en/rewrite/migrating.html#voice-changes

Vexs commented 6 years ago

What? it works just fine.

Uh, @Zenrac could you put your code in a gist/link us to it? It's not really easy to diagnose what's up with just this.

Rapptz commented 6 years ago

To properly report state bugs such as these, I require logging to be turned on and to be posted here along with tracebacks. Otherwise there's really not much I can do here except throw random guesses. Networks can be unpredictable and Discord is not known to be consistent.

Provide more information for this to be serviceable.

Zenrac commented 6 years ago

I tried to get some tracebacks, and I think I found a part of the answer :

Sometimes when the discord servers are laggy, I switch the guild region, particularly during the last few days. So I tested if it is the source of my problem. My bot was connected to a voice channel, playing a song, I switched the guild region, and it stopped the song, moreover, the bot was stuck in the voice channel and I got some tracebacks on my terminal. (btw, I don't have any tracebacks when the bot is not connected to voice neither when I go back to the previous region)

[2018-03-03 17:02:33,856] - WARNING: [Guild] "Test bot" changed regions : eu-west --> eu-central
Task exception was never retrieved
future: <Task finished coro=<VoiceClient._create_socket() done, defined at C:\Users\Zenrac\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\voice_client.py:165> exception=WebSocketProtocolError('Invalid status code',)>
Traceback (most recent call last):
  File "C:\Users\Zenrac\AppData\Local\Programs\Python\Python36-32\lib\site-packages\discord\voice_client.py", line 193, in _create_socket
    yield from self.ws.close(1006)
  File "C:\Users\Zenrac\AppData\Local\Programs\Python\Python36-32\lib\site-packages\websockets\protocol.py", line 366, in close
    frame_data = serialize_close(code, reason)
  File "C:\Users\Zenrac\AppData\Local\Programs\Python\Python36-32\lib\site-packages\websockets\framing.py", line 285, in serialize_close
    check_close(code)
  File "C:\Users\Zenrac\AppData\Local\Programs\Python\Python36-32\lib\site-packages\websockets\framing.py", line 295, in check_close
    raise WebSocketProtocolError("Invalid status code")
websockets.exceptions.WebSocketProtocolError: Invalid status code

I think the same problem can happens if the bot is kicked from the guild and invited back. Why it is happening ?

Rapptz commented 6 years ago

This should be fixed.

Reopen if you can get it to happen again.

Zenrac commented 6 years ago

Hi again,

I don't know if it's an issue but I'm getting some weird logs when a guild merge to another guild region.

[2018-06-21 01:01:33,328] - WARNING: [Guilds] "test server" changed regions: eu-west -> eu-central
.
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/gateway.py", line 677, in poll_event
    msg = await asyncio.wait_for(self.recv(), timeout=30.0, loop=self.loop)
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/usr/local/lib/python3.6/site-packages/websockets/protocol.py", line 352, in recv
    yield from self.ensure_open()
  File "/usr/local/lib/python3.6/site-packages/websockets/protocol.py", line 503, in ensure_open
    self.close_code, self.close_reason) from self.transfer_data_exc
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 4000 (private use), no reason

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/discord/voice_client.py", line 227, in poll_voice_ws
    await self.ws.poll_event()
  File "/usr/local/lib/python3.6/site-packages/discord/gateway.py", line 680, in poll_event
    raise ConnectionClosed(e, shard_id=None) from e
discord.errors.ConnectionClosed: WebSocket connection is closed: code = 4000 (private use), no reason

There is no problem, the voice disconnect/reconnect itself and the song doesn't stop or crash. But I'm still having this annoying logs. Maybe it is a dep bug ?

utlandr commented 5 years ago

@Zenrac did you eventually find a fix for this? I am also getting this weird intermittent reconnect/disconnect.

Zenrac commented 5 years ago

I'm not using ffmpeg/discord.py to handle voice players anymore