#ConnectAsync() returns null

1 messages · Page 1 of 1 (latest)

frozen burrow
#

I want to play an mp3 file in voice, but I cant because audioClient is always null

#

Installed packages:
Discord.Net 3.8.1
Microsoft.Extensions.DependencyInjection 7.0.0

#

screenshot from \hk417\bin\Debug\net6.0

willow vale
#

@frozen burrow
First of all, I don't think you need to set external to true.

Secondly, try doing it the way that the documentation example does it (https://discordnet.dev/guides/voice/sending-voice.html)

private async Task SlashCommandHandler(SocketSlashCommand command)
{
    if (command.CommandName == "name")
    {
        var channel = (command.User as IGuildUser)?.VoiceChannel;
        
        using (var ffmpeg = CreateStream("C:\audiofile.mp3"))
        using (var output = ffmpeg.StandardOutput.BaseStream)
        using (var discord = client.CreatePCMStream(AudioApplication.Mixed))
        {
            try { await output.CopyToAsync(discord); }
            finally { await discord.FlushAsync(); }
        }
    }
}

private Process CreateStream(string path)
{
    return Process.Start(new ProcessStartInfo
    {
        FileName = "ffmpeg",
        Arguments = $"-hide_banner -loglevel panic -i \"{path}\" -ac 2 -f s16le -ar 48000 pipe:1",
        UseShellExecute = false,
        RedirectStandardOutput = true,
    });
}

Third, although unrelated to your question, you do not need all the files for libopus/libsodium. You only need the two binary files, libopus.dll and libsodium.dll. You can delete the rest

frozen burrow
#

If I use audioClient without external:true bot joins to voice and doesnt execute any code until it disconnects with this error