Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.

Refactor and Stabilize Music Module - #2

Draft
google-labs-jules[bot] wants to merge 1 commit into
mainfrom
refactor-and-stabilize-music-module
Draft

Refactor and Stabilize Music Module#2
google-labs-jules[bot] wants to merge 1 commit into
mainfrom
refactor-and-stabilize-music-module

Conversation

@google-labs-jules

Copy link
Copy Markdown

This commit provides a comprehensive overhaul of the music module to fix numerous bugs and improve its overall stability, maintainability, and user experience.

The following critical bugs have been addressed:

  • Random Song Skipping: A race condition between the library's autoSkip feature and a manual player.play() call in the trackEnd event handler was causing songs to be skipped. This has been resolved by removing the manual call.
  • Playback Stalling: Songs would stop mid-playback due to unhandled trackStuck and trackError events. The module now correctly handles these events by skipping to the next song.
  • Command Logic Bugs: The /skipto, /loop, and /volume commands had incorrect implementations that have now been fixed.
  • Race Condition in /play: A race condition that could cause a crash if /stop was called during a song search has been resolved by re-validating the player state.

In addition to bug fixes, the following improvements have been made:

  • Code Quality: Duplicated code has been refactored into a shared utility file.
  • User Experience: The /stop command now behaves more predictably (clearing the queue without disconnecting), and the /queue list command is now protected from performance issues with very large queues.
  • Code Clarity: A conflicting queueEnd handler has been removed to make the bot's behavior more clear and reliant on its configuration.

This commit includes a full suite of fixes and improvements to the music module, addressing critical bugs, improving code quality, and enhancing stability.

Key Bug Fixes:
- Fixes a race condition in the `trackEnd` event that caused random song skipping by removing a redundant `player.play()` call.
- Adds `trackStuck` and `trackError` event handlers to gracefully skip songs that fail to play, fixing issues where playback would stop mid-song.
- Fixes the `/queue skipto` command to correctly modify the queue.
- Fixes a validation conflict in the `/volume` command.
- Fixes the `/loop` command to use the correct API method.
- Fixes a race condition in the `/play` command by re-validating player state after an async search.

Refactoring and Improvements:
- Refactors duplicated `formatDuration` and `generateProgressBar` functions into a shared utility file.
- Corrects the `/stop` command's behavior to no longer disconnect the bot.
- Adds a guard against seeking in live streams.
- Improves performance of the `/queue list` command for very large queues.
- Removes a conflicting `queueEnd` event handler in favor of the configured `onEmptyQueue` option.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants