diff --git a/packages/client-discord/src/voice.ts b/packages/client-discord/src/voice.ts index 97f2a81b6e..a85e0f73d2 100644 --- a/packages/client-discord/src/voice.ts +++ b/packages/client-discord/src/voice.ts @@ -25,7 +25,7 @@ import { VoiceConnectionStatus, createAudioPlayer, createAudioResource, - getVoiceConnection, + getVoiceConnections, joinVoiceChannel, entersState, } from "@discordjs/voice"; @@ -194,7 +194,9 @@ export class VoiceManager extends EventEmitter { } async joinChannel(channel: BaseGuildVoiceChannel) { - const oldConnection = getVoiceConnection(channel.guildId as string); + const oldConnection = this.getVoiceConnection( + channel.guildId as string + ); if (oldConnection) { try { oldConnection.destroy(); @@ -212,6 +214,7 @@ export class VoiceManager extends EventEmitter { adapterCreator: channel.guild.voiceAdapterCreator as any, selfDeaf: false, selfMute: false, + group: this.client.user.id, }); try { @@ -328,6 +331,17 @@ export class VoiceManager extends EventEmitter { } } + private getVoiceConnection(guildId: string) { + const connections = getVoiceConnections(this.client.user.id); + if (!connections) { + return; + } + const connection = [...connections.values()].find( + (connection) => connection.joinConfig.guildId === guildId + ); + return connection; + } + private async monitorMember( member: GuildMember, channel: BaseGuildVoiceChannel @@ -335,7 +349,7 @@ export class VoiceManager extends EventEmitter { const userId = member?.id; const userName = member?.user?.username; const name = member?.user?.displayName; - const connection = getVoiceConnection(member?.guild?.id); + const connection = this.getVoiceConnection(member?.guild?.id); const receiveStream = connection?.receiver.subscribe(userId, { autoDestroy: true, emitClose: true, @@ -1069,7 +1083,7 @@ export class VoiceManager extends EventEmitter { } async handleLeaveChannelCommand(interaction: any) { - const connection = getVoiceConnection(interaction.guildId as any); + const connection = this.getVoiceConnection(interaction.guildId as any); if (!connection) { await interaction.reply("Not currently in a voice channel.");