Connection
The Connection class makes you able to play a stream in a voice channel.
Creating a connection
A connection can easily be created by using the Connection class. The Connection class works different than the Player and the AudioManager class. The Connection class will make the bot join the voice channel immediately when the Connection class is being called. The Player and AudioManager classes make you join a voice channel when you start playing a song.
The Connection class requires the channel
parameter and has an optional options
parameter. The channel
parameter is the voice channel that the bot needs to join. The options
parameter has the following options:
selfDeaf: If the bot should deaf itself. (default is
true
)selfMute: If the bot should mute itself. (default is
false
)
Play a stream
You can play a stream by using the play function and returns a Promise. The function requires the stream
parameter and has an optional options
parameter. The stream parameter is the stream
that you want to play. The options
parameter has the following options:
noListeners: If there are no members listening in the voice channel.
play: Continues playing the stream. (default and recommended)
pause: Pauses the stream until someone joins again.
stop: Stops the player and leaves the voice channel.
volume: The volume of the stream. Max 1, min 0.
audiotype: The audio type of the stream.
'arbitrary': For mp3 audio (default)
'ogg/opus': For ogg audio
'webm/opus': For webm audio
'opus': For opus audio
'raw': For raw audio
Subscribe to a broadcast
You can subscribe to a Broadcast by using the subscribe function. A Broadcast makes you able to create one source and play it in multiple guilds. The subscribe function only requires the broadcast
parameter which is the Broadcast itself which you can create with the Broadcast class. The function returns a Promise which will be fullfilled if the connection successfully subscribed to the broadcast.
Unsubscribe to a broadcast
You can easily unsubscribe by using the unsubscribe function.
Changing the volume
You can change the volume by using the volume function. It requires the volume
parameter which will be the volume of the stream that's playing. The volume must be at least 0 and may not be higher than 1.
This function does not work for broadcasts! Broadcasts have their own volume function.
Disconnect from a connection
You can disconnect from a connection by using the disconnect function.
If the connection is subscribed to a broadcast the disconnect function will automatically unsubscribe from the broadcast.
Destroy a connection
You can destroy a connection by using the destroy function.
If the connection is subscribed to a broadcast, the destroy function will automatically unsubscribe from the broadcast.
Pause a stream
You can pause a stream by using the pause function.
This function does not work for broadcasts! Broadcasts have their own pause function.
Resuming a stream
You can resume a stream by using the resume function.
This function does not work for broadcasts! Broadcasts have their own resume function.
Event listeners
The Connection class also has 6 events:
play: When the stream of the connection starts playing.
Returns the stream that plays (not for broadcasts)
end: When the stream of the connection ended.
Returns the stream that ended (not for broadcasts)
disconnect: When the bot got disconnected from the connection.
Returns the channel id
destroy: When the connection got destroyed.
Returns the channel id
subscribe: When the connection got subscribed to a broadcast.
unsubscribe: When the connection got unsubscribed from a broadcast.
Last updated