@@ -25,7 +25,7 @@ import {
25
25
VoiceConnectionStatus ,
26
26
createAudioPlayer ,
27
27
createAudioResource ,
28
- getVoiceConnection ,
28
+ getVoiceConnections ,
29
29
joinVoiceChannel ,
30
30
entersState ,
31
31
} from "@discordjs/voice" ;
@@ -194,7 +194,9 @@ export class VoiceManager extends EventEmitter {
194
194
}
195
195
196
196
async joinChannel ( channel : BaseGuildVoiceChannel ) {
197
- const oldConnection = getVoiceConnection ( channel . guildId as string ) ;
197
+ const oldConnection = this . getVoiceConnection (
198
+ channel . guildId as string
199
+ ) ;
198
200
if ( oldConnection ) {
199
201
try {
200
202
oldConnection . destroy ( ) ;
@@ -212,6 +214,7 @@ export class VoiceManager extends EventEmitter {
212
214
adapterCreator : channel . guild . voiceAdapterCreator as any ,
213
215
selfDeaf : false ,
214
216
selfMute : false ,
217
+ group : this . client . user . id ,
215
218
} ) ;
216
219
217
220
try {
@@ -328,14 +331,25 @@ export class VoiceManager extends EventEmitter {
328
331
}
329
332
}
330
333
334
+ private getVoiceConnection ( guildId : string ) {
335
+ const connections = getVoiceConnections ( this . client . user . id ) ;
336
+ if ( ! connections ) {
337
+ return ;
338
+ }
339
+ const connection = [ ...connections . values ( ) ] . find (
340
+ ( connection ) => connection . joinConfig . guildId === guildId
341
+ ) ;
342
+ return connection ;
343
+ }
344
+
331
345
private async monitorMember (
332
346
member : GuildMember ,
333
347
channel : BaseGuildVoiceChannel
334
348
) {
335
349
const userId = member ?. id ;
336
350
const userName = member ?. user ?. username ;
337
351
const name = member ?. user ?. displayName ;
338
- const connection = getVoiceConnection ( member ?. guild ?. id ) ;
352
+ const connection = this . getVoiceConnection ( member ?. guild ?. id ) ;
339
353
const receiveStream = connection ?. receiver . subscribe ( userId , {
340
354
autoDestroy : true ,
341
355
emitClose : true ,
@@ -1069,7 +1083,7 @@ export class VoiceManager extends EventEmitter {
1069
1083
}
1070
1084
1071
1085
async handleLeaveChannelCommand ( interaction : any ) {
1072
- const connection = getVoiceConnection ( interaction . guildId as any ) ;
1086
+ const connection = this . getVoiceConnection ( interaction . guildId as any ) ;
1073
1087
1074
1088
if ( ! connection ) {
1075
1089
await interaction . reply ( "Not currently in a voice channel." ) ;
0 commit comments