Skip to content

Commit

Permalink
feat: move voice channel function
Browse files Browse the repository at this point in the history
  • Loading branch information
0t4u committed Nov 12, 2024
1 parent 161b54c commit 852be8f
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/Shoukaku.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// eslint-disable-next-line import-x/no-cycle
import { Connector } from './connectors/Connector';
// eslint-disable-next-line import-x/no-cycle
import { ShoukakuDefaults, VoiceState } from './Constants';
import { ShoukakuDefaults, State, VoiceState } from './Constants';
// eslint-disable-next-line import-x/no-cycle
import { Connection } from './guild/Connection';
// eslint-disable-next-line import-x/no-cycle
Expand Down Expand Up @@ -297,6 +297,37 @@ export class Shoukaku extends TypedEventEmitter<ShoukakuEvents> {
}
}

/**
* Leaves current voice channel and joins a new one
* @param guildId GuildId in which the ChannelId of the voice channel is located
* @param channelId Id of channel to move to
* @throws {@link Error} When guild does not have an existing connection, or could not be moved
* @returns The moved player
*/
public async moveVoiceChannel(guildId: string, channelId: string) {
const connection = this.connections.get(guildId);
if (!connection)
throw new Error('This guild does not have an existing connection');

if (connection.channelId === channelId) return;

try {
connection.setStateUpdate({
session_id: connection.sessionId!,
channel_id: channelId,
self_deaf: connection.deafened,
self_mute: connection.muted
});
connection.state = State.RECONNECTING;
await connection.connect();

// player should get updated automagically as connectionUpdate is fired
return this.players.get(guildId);
} catch (error) {
throw new Error(`Could not move to new voice channel with id ${channelId}`, { cause: error });
}
}

/**
* Cleans the disconnected lavalink node
* @param node The node to clean
Expand Down

0 comments on commit 852be8f

Please sign in to comment.