Listen for Discord disconnect event and make sure it's handled (#259)

This commit is contained in:
sssionek 2023-11-25 22:23:07 +01:00 committed by GitHub
parent 941bc8745e
commit cdb8508226
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -9,6 +9,7 @@ import {
joinVoiceChannel, joinVoiceChannel,
NoSubscriberBehavior, NoSubscriberBehavior,
VoiceConnection, VoiceConnection,
VoiceConnectionStatus,
} from '@discordjs/voice'; } from '@discordjs/voice';
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
@ -96,7 +97,12 @@ export class DiscordVoiceService {
if (this.voiceConnection === undefined) { if (this.voiceConnection === undefined) {
this.voiceConnection = getVoiceConnection(member.guild.id); this.voiceConnection = getVoiceConnection(member.guild.id);
} }
this.voiceConnection?.on(VoiceConnectionStatus.Disconnected, () => {
if (this.voiceConnection !== undefined) {
const playlist = this.playbackService.getPlaylistOrDefault().clear();
this.disconnect();
}
});
return { return {
success: true, success: true,
reply: {}, reply: {},