Skip to content

Commit

Permalink
fix: on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Googlefan256 committed Jan 14, 2024
1 parent a4efdce commit 8f685b8
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,28 @@ export class Player {
);
const stream = await dl(options.id);
this.player.play(stream);
const onError = (e: any) => {
error(e);
this.player.off("stateChange", listener);
this.player.off("error", onError);
this.play();
};
const listener = (
state: AudioPlayerState,
newState: AudioPlayerState,
) => {
if (state.status === "playing" && newState.status === "idle") {
info(`Finished playing ${options.title}.`);
this.player.off("stateChange", listener);
this.player.off("error", onError);
if (this.queuelooping) {
this.queue.push(options);
}
this.play();
}
};
this.player.on("stateChange", listener);
this.player.on("error", (e) => {
error(e);
this.player.off("stateChange", listener);
this.play();
});
this.player.on("error", onError);
} catch (e) {
console.error(e);
this.play();
Expand Down

0 comments on commit 8f685b8

Please sign in to comment.