Skip to main content
The AudioManager interface manages audio connections to voice channels and controls audio handlers for sending and receiving audio in a Guild.
Audio receiving requires the DAVE (Discord Audio Video Encryption) protocol. See the Discord documentation for more information.

Getting an AudioManager

Retrieve the AudioManager from a Guild:
Guild guild = event.getGuild();
AudioManager audioManager = guild.getAudioManager();

Connection Methods

openAudioConnection

Opens an audio connection to a voice channel, or moves an existing connection.
void openAudioConnection(AudioChannel channel)
channel
AudioChannel
required
The voice or stage channel to connect to
Example:
VoiceChannel voiceChannel = guild.getVoiceChannelById("123456789");
audioManager.openAudioConnection(voiceChannel);

closeAudioConnection

Closes the current audio connection.
void closeAudioConnection()
Example:
audioManager.closeAudioConnection();

isConnected

Checks if there is an active audio connection.
boolean isConnected()
returns
boolean
true if an active audio connection exists

getConnectedChannel

Gets the currently connected audio channel.
AudioChannelUnion getConnectedChannel()
returns
AudioChannelUnion
The connected channel, or null if not connected

Audio Handler Methods

setSendingHandler

Sets the handler that provides audio data to send.
void setSendingHandler(AudioSendHandler handler)
handler
AudioSendHandler
The audio send handler, or null to remove
Example:
AudioSendHandler sendHandler = new MyAudioSendHandler();
audioManager.setSendingHandler(sendHandler);
JDA recommends LavaPlayer as an AudioSendHandler implementation.

getSendingHandler

Gets the current audio send handler.
AudioSendHandler getSendingHandler()
returns
AudioSendHandler
The current send handler, or null if none is set

setReceivingHandler

Sets the handler that processes received audio data.
void setReceivingHandler(AudioReceiveHandler handler)
handler
AudioReceiveHandler
The audio receive handler, or null to remove
Audio receiving requires Discord’s DAVE protocol support. This feature may have limited availability.
Example:
AudioReceiveHandler receiveHandler = new MyAudioReceiveHandler();
audioManager.setReceivingHandler(receiveHandler);

getReceivingHandler

Gets the current audio receive handler.
AudioReceiveHandler getReceivingHandler()
returns
AudioReceiveHandler
The current receive handler, or null if none is set

Speaking Mode

setSpeakingMode

Sets the speaking mode for the audio connection.
void setSpeakingMode(Collection<SpeakingMode> mode)
void setSpeakingMode(SpeakingMode... mode)
mode
Collection<SpeakingMode>
required
The speaking modes to use (default: VOICE)
This is an incubating feature. Discord has not officially confirmed this will be available to bots.
Example:
audioManager.setSpeakingMode(SpeakingMode.VOICE, SpeakingMode.PRIORITY_SPEAKER);

getSpeakingMode

Gets the current speaking mode.
EnumSet<SpeakingMode> getSpeakingMode()
returns
EnumSet<SpeakingMode>
The current speaking modes

Connection Configuration

setConnectTimeout

Sets the connection timeout in milliseconds.
void setConnectTimeout(long timeout)
timeout
long
required
Timeout in milliseconds (default: 10000). Set to 0 to wait indefinitely.

getConnectTimeout

Gets the current connection timeout.
long getConnectTimeout()
returns
long
The connection timeout in milliseconds

setAutoReconnect

Sets whether to automatically reconnect on connection loss.
void setAutoReconnect(boolean shouldReconnect)
shouldReconnect
boolean
required
true to enable auto-reconnect (default)

isAutoReconnect

Checks if auto-reconnect is enabled.
boolean isAutoReconnect()
returns
boolean
true if auto-reconnect is enabled

Self State Methods

setSelfMuted

Sets whether the bot should be muted.
void setSelfMuted(boolean muted)
muted
boolean
required
true to mute the bot
When muted, audio packets from the AudioSendHandler will be ignored by Discord.

isSelfMuted

Checks if the bot is muted.
boolean isSelfMuted()
returns
boolean
true if the bot is muted

setSelfDeafened

Sets whether the bot should be deafened.
void setSelfDeafened(boolean deafened)
deafened
boolean
required
true to deafen the bot

isSelfDeafened

Checks if the bot is deafened.
boolean isSelfDeafened()
returns
boolean
true if the bot is deafened

Connection Status

getConnectionStatus

Gets the current connection status.
ConnectionStatus getConnectionStatus()
returns
ConnectionStatus
The current connection status

setConnectionListener

Sets a listener for connection status updates.
void setConnectionListener(ConnectionListener listener)
listener
ConnectionListener
The connection listener, or null to remove

getConnectionListener

Gets the current connection listener.
ConnectionListener getConnectionListener()
returns
ConnectionListener
The current connection listener, or null if none is set

Other Methods

getJDA

Gets the JDA instance this AudioManager belongs to.
JDA getJDA()
returns
JDA
The JDA instance

getGuild

Gets the Guild this AudioManager manages.
Guild getGuild()
returns
Guild
The Guild instance

Build docs developers (and LLMs) love