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 Sep 9, 2024
1 parent 33b9c28 commit d3a6622
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,4 +1,4 @@
import { ShoukakuDefaults, VoiceState } from './Constants';
import { ShoukakuDefaults, State, VoiceState } from './Constants';
import { Node, NodeEvents } from './node/Node';
import { Connector } from './connectors/Connector';
import { Constructor, mergeDefault, TypedEventEmitter } from './Utils';
Expand Down Expand Up @@ -292,6 +292,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 d3a6622

Please sign in to comment.