C#音乐机器人管道破裂

时间:2018-07-02 17:37:38

标签: c# discord discord.net

我的代码:

public class MusicModule : ModuleBase<SocketCommandContext>
{

    private static IAudioClient _audioclient;

    [Command("join", RunMode = RunMode.Async)]
    public async Task JoinChannel(IVoiceChannel channel = null)
    {
        channel = channel ?? (Context.User as IGuildUser)?.VoiceChannel;

        if (channel == null)
        {
            await ReplyAsync("Error: Couldn't find channel to join");
            return;
        }
        var audioClient = await channel.ConnectAsync();
    }

    [Command("leave", RunMode = RunMode.Async)]
    public async Task StopAsync(IVoiceChannel channel = null)
    {
        if (channel == null)
        {
            await ReplyAsync("Error: Couldn't find channel to leave");
            return;
        }
        await _audioclient.StopAsync();
    }

    [Command("play", RunMode = RunMode.Async)]
    public async Task PlaySong([Remainder] string url)
    {
        await ReplyAsync("**Song:** " + (url) + " Has now started.");

        // Create FFmpeg using the previous example
        var ffmpeg = CreateStream(url);
        var output = ffmpeg.StandardOutput.BaseStream;
        var stream = _audioclient.CreatePCMStream(AudioApplication.Mixed);
        await output.CopyToAsync(stream);
        await stream.FlushAsync();

    }

    private Process CreateStream(string url)
    {
        var ffmpeg = new ProcessStartInfo
        {
            FileName = "cmd.exe",
            Arguments = $"/C youtube-dl -o - {url} | ffmpeg -i pipe:0 -ac 2 -f s16le -ar 48000 pipe:1",
            UseShellExecute = false,
            RedirectStandardOutput = true,
        };
        return Process.Start(ffmpeg);
    }

    private async Task SendAsync(IAudioClient client, string path)
    {
        // Create FFmpeg using the previous example
        var ffmpeg = CreateStream(path);
        var output = ffmpeg.StandardOutput.BaseStream;
        var discord = client.CreatePCMStream(AudioApplication.Mixed);
        await output.CopyToAsync(discord);
        await discord.FlushAsync();
    }
}

}

我播放一首歌,我要么得到: https://gyazo.com/aca4573535a84108d498f3736e7871a9或: https://gyazo.com/7a7b07d333e9fb7646bb40856e47ec65

任何帮助将不胜感激! 我会玩(LINK) 它没有加入,但是在控制台中说它正在下载,然后说它是红色的BROKEN PIPE。

0 个答案:

没有答案
相关问题