Skip to content

Commit 12d7154

Browse files
committed
Improve troubleshooting guide
1 parent 98624f9 commit 12d7154

4 files changed

Lines changed: 84 additions & 5 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using NetCord.Gateway;
2+
using NetCord.Gateway.Voice;
3+
4+
namespace MyBot;
5+
6+
internal static class Examples
7+
{
8+
public static async Task ConnectWithLongerTimeoutAsync(GatewayClient client,
9+
ulong guildId,
10+
ulong channelId,
11+
VoiceClientConfiguration? configuration)
12+
{
13+
var voiceClient = await client.JoinVoiceChannelAsync(guildId, channelId, configuration, TimeSpan.FromSeconds(10));
14+
}
15+
16+
public static async Task KeepAliveAsync(VoiceClient voiceClient, CancellationToken cancellationToken)
17+
{
18+
using PeriodicTimer timer = new(TimeSpan.FromSeconds(30));
19+
20+
while (await timer.WaitForNextTickAsync(cancellationToken))
21+
await voiceClient.SendDatagramAsync(ReadOnlyMemory<byte>.Empty, cancellationToken);
22+
}
23+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\..\..\NetCord\NetCord.csproj" />
5+
</ItemGroup>
6+
7+
</Project>
Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,61 @@
11
# Troubleshooting
22

3-
Sometimes, you may encounter issues when working with audio.
3+
Working with audio can sometimes introduce unexpected issues. Below are common problems and their corresponding troubleshooting steps to help you resolve them.
44

5-
Below you can find some common issues, as well as some troubleshooting steps you can take to resolve them.
5+
## Missing Native Dependencies
6+
7+
If you encounter a @System.DllNotFoundException, it usually indicates missing or incompatible native dependencies. Refer to the [Native Dependencies](../basic-concepts/installing-native-dependencies.md) guide for steps on resolving this.
8+
9+
---
10+
11+
## Timeout When Connecting to Voice
12+
13+
If you experience a @System.TimeoutException when connecting to a voice channel, it typically stems from one of the following issues:
14+
15+
### Missing Permissions
16+
Ensure the bot has the @NetCord.Permissions.Connect permission in the target voice channel.
17+
18+
### Channel Capacity
19+
Check if the voice channel is full; the bot needs an available slot to join.
20+
21+
### Already Connected
22+
Verify that the bot isn't already active in the channel it is trying to join.
23+
24+
### Slow Network Connection
25+
@NetCord.Gateway.Voice.GatewayClientExtensions.JoinVoiceChannelAsync* has a default timeout of 2 seconds, which might be too brief for slower networks. You can extend this timeout (e.g., to 10 seconds) as shown below:
26+
[!code-cs[Join Voice Channel with Extended Timeout](Troubleshooting/Examples.cs#L13)]
27+
28+
---
29+
30+
## Audio Not Playing
31+
32+
If the bot connects to a voice channel but no audio is heard, verify the following:
33+
34+
### Missing Permissions
35+
Ensure the bot has the @NetCord.Permissions.Speak permission in the voice channel. The bot will appear as muted to other users if it lacks this permission.
36+
37+
### Speaking State
38+
Make sure to call @NetCord.Gateway.Voice.VoiceClient.EnterSpeakingStateAsync* with the correct @NetCord.Gateway.Voice.SpeakingFlags before sending audio.
39+
40+
---
641

742
## Failed to Get External Socket Address
843

9-
If you see the error "Failed to get the external socket address. Aborting the client." in your logs, it means that something blocks the IP Discovery response from Discord. This can be caused by various reasons, such as firewall settings or router configurations. If you encounter this issue, try using for example your mobile phone's hotspot to see if the issue is related to your router configuration. If it works on the hotspot, you may need to check your router's settings.
44+
If you see the error `Failed to get the external socket address. Aborting the client.` in your logs, something is blocking the IP Discovery request or response.
45+
46+
This is typically caused by firewall restrictions or router configurations. To diagnose whether it's a local network issue, try connecting the bot through a different network, such as a mobile hotspot.
47+
48+
---
49+
50+
## Receiving Audio Stops After Some Time
51+
52+
If audio suddenly cuts out after working normally for a while, consider these common causes:
53+
54+
### UDP Flood Protection
55+
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.
1056

11-
## Audio Stops After Some Time
57+
### Closed UDP Socket
58+
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.
1259

13-
If you receive audio for some time and then it suddenly stops, it may be caused by your router blocking the packets after some time. This can be caused by the router's UDP flood protection. You can try disabling this feature in your router's settings to see if it resolves the issue.
60+
Sending a small, empty data packet at regular intervals will ensure the UDP connection stays open, as demonstrated below:
61+
[!code-cs[Keep Alive](Troubleshooting/Examples.cs#L18-L21)]

NetCord.slnx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<Project Path="Documentation/guides/voice/Voice/Voice.csproj" />
6262
<Project Path="Documentation/guides/voice/VoiceSetup/VoiceSetup.csproj" />
6363
<Project Path="Documentation/guides/voice/VoiceConnection/VoiceConnection.csproj" />
64+
<Project Path="Documentation/guides/voice/Troubleshooting/Troubleshooting.csproj" />
6465
</Folder>
6566
<Folder Name="/Hosting/">
6667
<Project Path="Hosting/NetCord.Hosting.AspNetCore/NetCord.Hosting.AspNetCore.csproj" />

0 commit comments

Comments
 (0)