Fix music player crash if resource can't be stream

This commit is contained in:
2022-03-03 22:37:41 +07:00
parent 0e37c89f8d
commit d7e5f5045f
2 changed files with 37 additions and 10 deletions
+14 -8
View File
@@ -167,14 +167,20 @@ export class DiscordMusicPlayerInstance {
public async playTrack(track: ValidTracks) {
if (!this.voiceConnection) throw new Error("No voice connection");
const stream = await playdl.stream(track.url);
const resource = createAudioResource(stream.stream, {
inputType: stream.type
});
this.player.play(resource)
this.voiceConnection.subscribe(this.player)
try {
const stream = await playdl.stream(track.url);
const resource = createAudioResource(stream.stream, {
inputType: stream.type
});
this.player.play(resource)
this.voiceConnection.subscribe(this.player)
} catch (error: any) {
this.events.emit('error', new PlayerErrorEvent(this, error));
this.skipTrack();
}
}
public async skipTrack() {