Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move voice channel function #200

Merged
merged 2 commits into from
Nov 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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