VoiceConnection

VoiceConnection

Represents a voice connection

Constructor

new VoiceConnection()

Properties:
Properties
Name Type Attributes Description
channelID String

The ID of the voice connection's current channel

connecting Boolean

Whether the voice connection is connecting

current Object <nullable>

The state of the currently playing stream

Properties
Name Type Description
options Object

The custom options for the current stream

Name Type Attributes Description
encoderArgs Array.<String> <nullable>

Additional encoder parameters to pass to ffmpeg/avconv (after -i)

format String <nullable>

The format of the resource. If null, FFmpeg will attempt to guess and play the format. Available options: "dca", "ogg", "webm", "pcm", "opusPackets", null

frameDuration Number <nullable>

The resource opus frame duration (required for DCA/Ogg)

frameSize Number <nullable>

The resource opus frame size

inlineVolume Boolean <nullable>

Whether to enable on-the-fly volume changing. Note that enabling this leads to increased CPU usage

inputArgs Array.<String> <nullable>

Additional input parameters to pass to ffmpeg/avconv (before -i)

sampleRate Number <nullable>

The resource audio sampling rate

voiceDataTimeout Number <nullable>

Timeout when waiting for voice data (-1 for no timeout)

pausedTime Number

How long the current stream has been paused for, in milliseconds

pausedTimestamp Number

The timestamp of the most recent pause

playTime Number

How long the current stream has been playing for, in milliseconds

startTime Number

The timestamp of the start of the current stream

id String

The ID of the voice connection (guild ID)

paused Boolean

Whether the voice connection is paused

playing Boolean

Whether the voice connection is playing something

ready Boolean

Whether the voice connection is ready

resuming Boolean

Whether the voice connection is waiting for resuming

volume Number

The current volume level of the connection

Source:

Extends

  • EventEmitter

Methods

_sendAudioPacket()

Deprecated:
  • Yes
Source:

pause()

Pause sending audio (if playing)

Source:

play(resource, optionsopt)

Play an audio or video resource. If playing from a non-opus resource, FFMPEG should be compiled with --enable-libopus for best performance. If playing from HTTPS, FFMPEG must be compiled with --enable-openssl

Source:
Parameters:
Name Type Attributes Description
resource ReadableStream | String

The audio or video resource, either a ReadableStream, URL, or file path

options Object <optional>

Music options

Name Type Attributes Default Description
encoderArgs Array.<String> <optional>

Additional encoder parameters to pass to ffmpeg/avconv (after -i)

format String <optional>

The format of the resource. If null, FFmpeg will attempt to guess and play the format. Available options: "dca", "ogg", "webm", "pcm", null

frameDuration Number <optional>
20

The resource opus frame duration (required for DCA/Ogg)

frameSize Number <optional>
2880

The resource opus frame size

inlineVolume Boolean <optional>
false

Whether to enable on-the-fly volume changing. Note that enabling this leads to increased CPU usage

inputArgs Array.<String> <optional>

Additional input parameters to pass to ffmpeg/avconv (before -i)

pcmSize Number <optional>
options.frameSize*2*this.channels

The PCM size if the "pcm" format is used

samplingRate Number <optional>
48000

The resource audio sampling rate

voiceDataTimeout Number <optional>
2000

Timeout when waiting for voice data (-1 for no timeout)

receive(typeopt) → {VoiceDataStream}

Generate a receive stream for the voice connection.

Source:
Parameters:
Name Type Attributes Default Description
type String <optional>
"pcm"

The desired voice data type, either "opus" or "pcm"

Returns:
Type:
VoiceDataStream

resume()

Resume sending audio (if paused)

Source:

sendAudioFrame(frame, frameSizeopt)

Send a packet containing an Opus audio frame

Source:
Parameters:
Name Type Attributes Description
frame Buffer

The Opus audio frame

frameSize Number <optional>

The size (in samples) of the Opus audio frame

sendUDPPacket(packet)

Send a packet through the connection's UDP socket. The packet is dropped if the socket isn't established

Source:
Parameters:
Name Type Description
packet Buffer

The packet data

setVolume(volumeopt)

Modify the output volume of the current stream (if inlineVolume is enabled for the current stream)

Source:
Parameters:
Name Type Attributes Default Description
volume Number <optional>
1.0

The desired volume. 0.0 is 0%, 1.0 is 100%, 2.0 is 200%, etc. It is not recommended to go above 2.0

stopPlaying()

Stop the bot from sending audio

Source:

switchChannel(channelID)

Switch the voice channel the bot is in. The channel to switch to must be in the same guild as the current voice channel

Source:
Parameters:
Name Type Description
channelID String

The ID of the voice channel

updateVoiceState(selfMute, selfDeaf)

Update the bot's voice state

Source:
Parameters:
Name Type Description
selfMute Boolean

Whether the bot muted itself or not (audio receiving is unaffected)

selfDeaf Boolean

Whether the bot deafened itself or not (audio sending is unaffected)

Events

connect

Fired when the voice connection connects

Source:

debug

Fired when stuff happens and gives more info

Properties:
Name Type Description
message String

The debug message

Source:

disconnect

Fired when the voice connection disconnects

Properties:
Name Type Attributes Description
error Error <nullable>

The error, if any

Source:

end

Fired when the voice connection finishes playing a stream

Source:

error

Fired when the voice connection encounters an error. This event should be handled by users

Properties:
Name Type Description
err Error

The error object

Source:

pong

Fired when the voice connection receives a pong

Properties:
Name Type Description
latency Number

The current latency in milliseconds

Source:

ready

Fired when the voice connection turns ready

Source:

speakingStart

Fired when a user begins speaking

Properties:
Name Type Description
userID String

The ID of the user that began speaking

Source:

speakingStop

Fired when a user stops speaking

Properties:
Name Type Description
userID String

The ID of the user that stopped speaking

Source:

start

Fired when the voice connection starts playing a stream

Source:

userDisconnect

Fired when a user disconnects from the voice server

Properties:
Name Type Description
userID String

The ID of the user that disconnected

Source:

usersConnect

Fired when one or more clients connect to the voice channel

Properties:
Name Type Description
userIDs Array.<String>

The IDs of the users that connected

Source:

warn

Fired to warn of something weird but non-breaking happening

Properties:
Name Type Description
message String

The warning message

Source: