Appearance
VoiceManager
Package: @erinjs/voice
Manages voice connections. Use getVoiceManager(client) to obtain an instance.
Constructor
| Name | Type | Optional | Description |
|---|---|---|---|
client | Client | No | |
options | VoiceManagerOptions | No |
Properties
| Name | Type | Readonly | Optional | Description |
|---|---|---|---|---|
client | Client | Yes | No | |
connectionIds | Map<string, string> | Yes | No | channel_id -> connection_id (from VoiceServerUpdate; required for voice state updates) |
connections | any | Yes | No | channel_id -> connection (erin.js multi-channel: allows multiple connections per guild) |
pending | Map<string, { channel: VoiceChannel; resolve: (c: VoiceConnection | LiveKitRtcConnection) => void; reject: (e: Error) => void; server?: any; state?: any; }> | Yes | No | channel_id -> pending join |
shardId | number | Yes | No | |
voiceStates | VoiceStateMap | Yes | No | guild_id -> user_id -> channel_id |
Methods
getConnection()
Get the active voice connection for a channel or guild.
Returns: VoiceConnection | LiveKitRtcConnection | undefined
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
channelOrGuildId | string | No | Channel ID (primary) or guild ID (returns first connection in that guild) |
getVoiceChannelId()
Get the voice channel ID the user is currently in, or null if not in voice.
Returns: string | null
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
guildId | string | No | Guild ID to look up |
userId | string | No | User ID to look up |
handleVoiceServerUpdate()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
data | GatewayVoiceServerUpdateDispatchData | No |
handleVoiceStatesSync()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
data | { guildId: string; voiceStates: Array<{ user_id: string; channel_id: string | null; }>; } | No |
handleVoiceStateUpdate()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
data | GatewayVoiceStateUpdateDispatchData | No |
join() async
Join a voice channel. Resolves when the connection is ready. Supports multiple connections per guild (erin.js multi-channel).
Returns: Promise<VoiceConnection | LiveKitRtcConnection>
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
channel | VoiceChannel | No | The voice channel to join |
leave()
Leave all voice channels in a guild. With multi-channel support, disconnects from every channel in the guild.
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
guildId | string | No | Guild ID to leave |
leaveChannel()
Leave a specific voice channel by channel ID.
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
channelId | string | No | Channel ID to leave |
listParticipantsInChannel()
List participant user IDs currently in a specific voice channel.
Returns: string[]
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
guildId | string | No | |
channelId | string | No |
registerConnection()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
channelId | string | No | |
conn | VoiceConnection | LiveKitRtcConnection | No |
storeConnectionId()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
channelId | string | No | |
connectionId | string | null | undefined | No |
subscribeChannelParticipants()
Subscribe to inbound audio for all known participants currently in a voice channel. Only supported for LiveKit connections.
Returns: LiveKitReceiveSubscription[]
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
channelId | string | No | |
opts | { autoResubscribe?: boolean; } | Yes |
tryCompletePending()
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
channelId | string | No | |
pending | { channel: VoiceChannel; resolve: (c: VoiceConnection | LiveKitRtcConnection) => void; reject: (e: Error) => void; server?: GatewayVoiceServerUpdateDispatchData; state?: GatewayVoiceStateUpdateDispatchData; } | No |
updateVoiceState()
Update voice state (e.g. self_stream, self_video) while in a channel. Sends a VoiceStateUpdate to the gateway so the server and clients see the change. Requires connection_id (from VoiceServerUpdate); without it, the gateway would treat the update as a new join and trigger a new VoiceServerUpdate, causing connection loops.
Returns: void
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
channelId | string | No | Channel ID (connection key) |
partial | { self_stream?: boolean; self_video?: boolean; self_mute?: boolean; self_deaf?: boolean; } | No | Partial voice state to update (self_stream, self_video, self_mute, self_deaf) |
uploadStreamPreview() async
Upload a placeholder stream preview so the preview URL returns 200 instead of 404.
Returns: Promise<void>
Parameters:
| Name | Type | Optional | Description |
|---|---|---|---|
channelId | string | No | |
conn | VoiceConnection | LiveKitRtcConnection | No |