Table of Contents

Troubleshooting

Working with audio can sometimes introduce unexpected issues. Below are common problems and their corresponding troubleshooting steps to help you resolve them.

Missing Native Dependencies

If you encounter a DllNotFoundException, it usually indicates missing or incompatible native dependencies. Refer to the Native Dependencies guide for steps on resolving this.


Timeout When Connecting to Voice

If you experience a TimeoutException when connecting to a voice channel, it typically stems from one of the following issues:

Missing Permissions

Ensure the bot has the Connect permission in the target voice channel.

Channel Capacity

Check if the voice channel is full; the bot needs an available slot to join.

Already Connected

Verify that the bot isn't already active in the channel it is trying to join.

Slow Network Connection

JoinVoiceChannelAsync has a default timeout of 5 seconds, which might be too brief for slower networks. You can extend this timeout (e.g., to 15 seconds) as shown below:

var voiceClient = await client.JoinVoiceChannelAsync(guildId, channelId, configuration, TimeSpan.FromSeconds(15));

Audio Not Playing

If the bot connects to a voice channel but no audio is heard, verify the following:

Missing Permissions

Ensure the bot has the Speak permission in the voice channel. The bot will appear as muted to other users if it lacks this permission.

Speaking State

Make sure to call EnterSpeakingStateAsync with the correct SpeakingFlags before sending audio.


Failed to Get External Socket Address

The log error Failed to get the external socket address. Aborting the client. indicates that external socket address discovery has failed. This is typically caused by firewall restrictions, router configurations, or slow network responses.

Try connecting the bot to a mobile hotspot to quickly determine if your local router or firewall settings are the culprit.

Alternatively, try increasing the default 5-second discovery timeout in the configuration as shown below:

VoiceClientConfiguration configuration = new()
{
    ExternalSocketAddressDiscoveryTimeout = TimeSpan.FromSeconds(15),
};

Receiving Audio Stops After Some Time

If audio suddenly cuts out after working normally for a while, consider these common causes:

UDP Flood Protection

Your firewall or router might be blocking UDP packets due to a built-in flood protection feature. Try disabling this feature in your router settings, or temporarily switch to a mobile hotspot to see if the issue is strictly related to your router's configuration.

Closed UDP Socket

Sockets can sometimes close automatically, especially if the bot is listening without transmitting any audio. You can prevent this by adjusting your firewall/NAT settings or by implementing a keep-alive mechanism.

Sending a small, empty data packet at regular intervals will ensure the UDP connection stays open, as demonstrated below:

using PeriodicTimer timer = new(TimeSpan.FromSeconds(30));

while (await timer.WaitForNextTickAsync(cancellationToken))
    await voiceClient.SendDatagramAsync(ReadOnlyMemory<byte>.Empty, cancellationToken);