Skip to content

Commit

Permalink
Fixed bug with disconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
Struck713 committed Jul 22, 2023
1 parent d1feaf2 commit 5c0125f
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/lib/voice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AudioPlayer, AudioPlayerStatus, AudioResource, createAudioPlayer, creat
import { VoiceBasedChannel } from "discord.js";
import ytdl from "ytdl-core";
import { YoutubeMetadata } from "./utils/youtube";
import { voiceManager } from "../app";

//const ytdl = new YTDLPWrap('C:/Users/Noah/Programming/JavaScript/BarbarianBot_v2/binaries/yt-dlp.exe');

Expand Down Expand Up @@ -30,6 +31,15 @@ export class VoiceManager {
return this.connections.find(connection => connection.guildId == guildId);
}

destroy = (guildId: string) => {
let connection = this.get(guildId);
if (!connection) return;

let index = this.connections.indexOf(connection);
if (index == -1) return;
this.connections.splice(index, 1);
}

}

export class VoiceConnection {
Expand Down Expand Up @@ -92,12 +102,16 @@ export class VoiceConnection {
if (!voiceConnection) return { type: VoiceConnectionStatusType.FAIL, message: "Not connected to a voice channel!"};

console.log(`[GUILD ${this.guildId}] [VC ${this.channelId}] DISCONNECTED - Disconnected from voice (probably due to inactivity)`)

this.audioPlayer.stop();
voiceConnection.disconnect();
voiceConnection.destroy();

this.playing = undefined;
this.queue = [];

if (this.timeout) clearInterval(this.timeout);
voiceManager.destroy(this.guildId);

return { type: VoiceConnectionStatusType.SUCCESS, message: "Disconnected from voice."};
}
Expand Down

0 comments on commit 5c0125f

Please sign in to comment.