Skip to content

[Bug]: Voice receiving broken #3188

@duckymomo360

Description

@duckymomo360

Check The Docs

  • I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • I verified the issue was caused by Discord.Net.

Check your intents

  • I double checked that I have the required intents.

Description

After the fix given in #3183 the bot can now connect to voice channels, however it now spews out errors regarding decrypting the audio stream when you try to read incoming frames.

Version

3.18.0-nightly.20250913.625

Working Version

No response

Logs

16:13:06 Discord     Discord.Net v3.18.0-nightly.20250913.625+8883596c31d61771d9c34964ac7eb2554a95277e (API v10)
16:13:06 Gateway     Connecting
16:13:06 Gateway     Connecting ApiClient
16:13:07 Rest        GET gateway/bot: 329.06 ms
16:13:07 Gateway     Received Hello
16:13:07 Gateway     Heartbeat Started
16:13:07 Gateway     Identifying
16:13:07 Gateway     Sent Heartbeat
16:13:07 Gateway     Sent Identify
16:13:07 Gateway     Received HeartbeatAck
16:13:07 Gateway     Latency = 94 ms
16:13:07 Gateway     Received Dispatch (READY)
16:13:07 Gateway     GuildDownloader Started
16:13:07 Gateway     You're using the GuildScheduledEvents gateway intent without listening to any events related to that intent, consider removing the intent from your config.
16:13:07 Gateway     You're using the GuildInvites gateway intent without listening to any events related to that intent, consider removing the intent from your config.
16:13:07 Gateway     Connected
16:13:07 Gateway     Raising Event
16:13:07 Gateway     Received Dispatch (GUILD_AVAILABLE)
16:13:07 Gateway     Connected to bot testing
16:13:08 Gateway     GuildDownloader Stopped
Registered commands
16:13:08 Gateway     Ready
16:13:14 Gateway     Received Dispatch (INTERACTION_CREATE)
16:13:15 Gateway     Received Dispatch (MESSAGE_CREATE)
16:13:15 Rest        POST channels/1036085200125427766/messages: 366.7 ms
16:13:24 Gateway     Received Dispatch (INTERACTION_CREATE)
16:13:24 Gateway     Sent VoiceStateUpdate
16:13:24 Gateway     Sent VoiceStateUpdate
16:13:24 Gateway     Received Dispatch (VOICE_STATE_UPDATE)
16:13:25 Gateway     Received Dispatch (VOICE_SERVER_UPDATE)
16:13:25 Audio #1    Connecting
16:13:25 Audio #1    Connecting ApiClient. Voice server: wss://c-sea01-384d940d.discord.media:2053
16:13:25 Audio #1    Received Hello
16:13:25 Audio #1    Listening on port 53977
16:13:25 Audio #1    Sending Identity
16:13:25 Audio #1    Sent Identify
16:13:25 Audio #1    Received Ready
16:13:25 Audio #1    Sent Discovery
16:13:25 Audio #1    Heartbeat Started
16:13:25 Audio #1    Sent Heartbeat
16:13:25 Audio #1    Received Discovery
16:13:25 Audio #1    Sent SelectProtocol
16:13:25 Audio #1    Received HeartbeatAck
16:13:25 Audio #1    Latency = 15 ms
16:13:25 Audio #1    Received SessionDescription
16:13:25 Audio #1    Sent Speaking
16:13:25 Audio #1    Keepalive Started
16:13:25 Audio #1    Connected
16:13:25 Audio #1    Raising Event
16:13:25 Audio #1    Unknown OpCode (15)
16:13:25 Gateway     Received Dispatch (MESSAGE_CREATE)
16:13:25 Rest        POST interactions/1417649620540199022/aW50ZXJhY3Rpb246MTQxNzY0OTYyMDU0MDE5OTAyMjppdFk0RnNzZ2lvclFBc1NLMklGY2l5SlZ4cXFtdTdBR2ZZaGtTNVEyQlAyY3ZBem5TRVVZSmxldUNuUHRPV3ZSbEliZTB2MHpUam5aN3Jzb0t6YTVkalNTOXkwOG9hUUUwcHpzejMzSUFYcEdvUzVSRUIzeDNDWVBnSHg3cnA3Wg/callback: 248.84 ms
16:13:25 Gateway     Received Dispatch (VOICE_STATE_UPDATE)
Stream Created: 204735759339487232
16:13:25 Audio #1    Malformed Frame
16:13:26 Audio #1    Received ClientConnect
16:13:26 Audio #1    Malformed Frame
16:13:26 Audio #1    Unknown SSRC 12178
16:13:26 Audio #1    Unknown SSRC 12178
16:13:26 Audio #1    Unknown SSRC 12178
16:13:26 Audio #1    Unknown SSRC 12178
16:13:26 Audio #1    Unknown SSRC 12178
16:13:26 Audio #1    Unknown SSRC 12178
16:13:26 Audio #1    Unknown SSRC 12178
16:13:26 Audio #1    Unknown SSRC 12178
16:13:26 Audio #1    Unknown SSRC 12178
16:13:26 Audio #1    Unknown SSRC 12178
16:13:26 Audio #1    Received Speaking
16:13:26 Audio #1    Malformed Frame:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Discord.Audio.Streams.SodiumDecryptStream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count, CancellationToken cancelToken)
   at System.IO.Stream.WriteAsync(Byte[] buffer, Int32 offset, Int32 count)
   at Discord.Audio.AudioClient.ProcessPacketAsync(Byte[] packet)
(^Theres like 100 more of these that I snipped out)
16:13:27 Audio #1    Malformed Frame
16:13:28 Audio #1    Malformed Frame
16:13:29 Audio #1    Malformed Frame
16:13:30 Gateway     Received Dispatch (VOICE_STATE_UPDATE)
16:13:30 Audio #1    Received ClientDisconnect
Error reading audio stream for user 204735759339487232: Cannot access a disposed object.
Object name: 'System.Threading.SemaphoreSlim'.
16:13:30 Audio #1    Malformed Frame
16:13:31 Audio #1    Malformed Frame

Sample

public class VoiceInteractions : InteractionModuleBase
{
    [CommandContextType(InteractionContextType.Guild)]
    [SlashCommand("join", "Join voice")]
    public async Task JoinVoiceCommand(IVoiceChannel? channel = null)
    {
        channel = channel ?? (Context.User as IGuildUser)?.VoiceChannel;
        if (channel == null) { await Context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return; }

        var audioClient = await channel.ConnectAsync();

        audioClient.StreamCreated += AudioClient_StreamCreated;

        await RespondAsync("Connected to voice", ephemeral: true);
    }

    private async Task AudioClient_StreamCreated(ulong userId, AudioInStream inStream)
    {
        Console.WriteLine("Stream Created: " + userId);
        
        _ = Task.Run(async () => await ReadAudioStream(userId, inStream));
    }

    private async Task ReadAudioStream(ulong userId, AudioInStream inStream)
    {
        try
        {
            while (true)
            {
                if (inStream.TryReadFrame(CancellationToken.None, out var frame))
                {
                    Console.WriteLine("Got frame: " + frame);
                }
            }
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error reading audio stream for user {userId}: {ex.Message}");
        }
    }
}

Packages

None

Environment

Windows 11 26100.6584 x64
.NET 9.0 (occurs in 6.0 too)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions