Open Marti2203 opened 1 week ago
@acr-bot
Here is a potential patch for reference:
diff --git a/discord/player.py b/discord/player.py
index 5b2c99d..b661a58 100644
--- a/discord/player.py
+++ b/discord/player.py
@@ -210,6 +210,9 @@ class FFmpegAudio(AudioSource):
raise ClientException(f'Popen failed: {exc.__class__.__name__}: {exc}') from exc
else:
return process
+ finally:
+ if process and process.returncode != 0:
+ raise ClientException(f'FFmpeg process exited with code {process.returncode}')
def _kill_process(self) -> None:
# this function gets called in __del__ so instance attributes might not even exist
@@ -729,42 +732,49 @@ class AudioPlayer(threading.Thread):
play_audio = client.send_audio_packet
self._speak(SpeakingState.voice)
- while not self._end.is_set():
- # are we paused?
- if not self._resumed.is_set():
- self.send_silence()
- # wait until we aren't
- self._resumed.wait()
- continue
-
- data = self.source.read()
+ try:
+ while not self._end.is_set():
+ # are we paused?
+ if not self._resumed.is_set():
+ self.send_silence()
+ # wait until we aren't
+ self._resumed.wait()
+ continue
+
+ data = self.source.read()
+
+ if not data:
+ self.stop()
+ break
+
+ # are we disconnected from voice?
+ if not client.is_connected():
+ _log.debug('Not connected, waiting for %ss...', client.timeout)
+ # wait until we are connected, but not forever
+ connected = client.wait_until_connected(client.timeout)
+ if self._end.is_set() or not connected:
+ _log.debug('Aborting playback')
+ return
+ _log.debug('Reconnected, resuming playback')
+ self._speak(SpeakingState.voice)
+ # reset our internal data
+ self.loops = 0
+ self._start = time.perf_counter()
+
+ play_audio(data, encode=not self.source.is_opus())
+ self.loops += 1
+ next_time = self._start + self.DELAY * self.loops
+ delay = max(0, self.DELAY + (next_time - time.perf_counter()))
+ time.sleep(delay)
+
+ except Exception as e:
+ self._current_error = e
+ self.stop()
- if not data:
- self.stop()
- break
-
- # are we disconnected from voice?
- if not client.is_connected():
- _log.debug('Not connected, waiting for %ss...', client.timeout)
- # wait until we are connected, but not forever
- connected = client.wait_until_connected(client.timeout)
- if self._end.is_set() or not connected:
- _log.debug('Aborting playback')
- return
- _log.debug('Reconnected, resuming playback')
- self._speak(SpeakingState.voice)
- # reset our internal data
- self.loops = 0
- self._start = time.perf_counter()
-
- play_audio(data, encode=not self.source.is_opus())
- self.loops += 1
- next_time = self._start + self.DELAY * self.loops
- delay = max(0, self.DELAY + (next_time - time.perf_counter()))
- time.sleep(delay)
-
- if client.is_connected():
- self.send_silence()
+ finally:
+ if client.is_connected():
+ self.send_silence()
+ self._call_after()
def run(self) -> None:
try:
This run costs 0.73 USD.
I want the patches to add a signature next to modified lines indicating that the line is repaired by AutoCodeRover, e.g. #This line brought to you by AutoCodeRover
@acr-bot
Summary
VoiceClient.play() doesn't pass FFMPEG error to 'after' function.
Reproduction Steps
I know from https://github.com/Rapptz/discord.py/issues/5131 that the session invalidation error is not a Discord.py error, however, the VoiceClient's play() function does not seem to be capturing and passing the FFMPEG error into my provided after function. I would like to notify when this error happens, so capturing this error would be very helpful. It also appears that Discord.py wrongly states that FFMPEG exited successfully, even when it exits with code 1, which by definition, is not successful.
Here is my current code and log results: Code:
Logs:
Minimal Reproducible Code
Expected Results
I expected the FFMPEG error to be passed to the after function
Actual Results
The error was not captured and passed to the after function
Intents
discord.Intents.default()
System Information
Python v3.10.12-final discord.py v2.3.2-final aiohttp v3.9.5 system info: Linux 5.15.0-112-generic https://github.com/Rapptz/discord.py/pull/122 SMP Thu May 23 07:48:21 UTC 2024
Checklist
Additional Context
No response