尝试通过语音通道播放youtube音频时,C#discord bot unknown操作码8

时间:2017-07-25 00:24:55

标签: c# discord.net

我目前正在研究C#discord.net 1.0.0 discord bot,我试图添加一个允许机器人通过语音聊天播放youtube音频的命令,但是当机器人加入语音聊天时尝试播放音频,我的控制台只返回:

16:57:42 Audio #1    Connecting
16:57:42 Audio #1    Unknown OpCode (8)
16:57:42 Audio #1    Connected

如果有人告诉我转到不和谐api,我已经去了那里,他们对我来说没什么帮助 但是,我的代码是:

using System.Threading.Tasks;
using Discord.Commands;
using Discord;
using Discordbot;
using System.Diagnostics;
using Discord.Audio;
using System;

public class AudioModule : ModuleBase<ICommandContext>
{
private readonly AudioService _service;
public static IAudioClient client;
private Process CreateStream(string url)
{
    Process currentsong = new Process();
    try
    {
        currentsong.StartInfo = new ProcessStartInfo
        {
            FileName = "youtube-dl.exe",
            Arguments = $"-o - {url} | ffmpeg -i pipe:0 -ac 2 -f s16le -ar 
 48000 pipe:1",
            UseShellExecute = false,
            RedirectStandardOutput = true,
            CreateNoWindow = true
        };
    }
    catch
    {
    }
    currentsong.Start();
    return currentsong;
    } 
 [Command("play", RunMode = RunMode.Async)]
 public async Task play(string url)
 {
    IVoiceChannel channel = (Context.User as IVoiceState).VoiceChannel;
    IAudioClient client = await channel.ConnectAsync();

    var output = CreateStream(url).StandardOutput.BaseStream;
    var stream = client.CreatePCMStream(AudioApplication.Music, 128 * 1024);
    await output.CopyToAsync(stream);
    await stream.FlushAsync().ConfigureAwait(false);
    }

   }

1 个答案:

答案 0 :(得分:0)

OpCode 8是网关Request Guild Members请求。发生Unkown OpCode 8的事实不应该阻碍你的机器人播放音乐,并且可以安全地忽略。

您可能希望检查您的流程是否正常工作

  currentsong.StartInfo = new ProcessStartInfo
    {
        FileName = "youtube-dl.exe",
        Arguments = $"-o - {url} | ffmpeg -i pipe:0 -ac 2 -f s16le -ar 48000 pipe:1",
        UseShellExecute = false,
        RedirectStandardOutput = true,
        CreateNoWindow = true
    };