【问题标题】:C# discord bot unknown opcode 8 when attempting to play youtube audio through voice channel尝试通过语音通道播放 youtube 音频时 C# discord bot 未知操作码 8
【发布时间】:2017-12-30 17:08:55
【问题描述】:

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

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

如果有人告诉我去 discord 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);
    }

   }

【问题讨论】:

  • 您在这里使用外壳(您使用管道等)...

标签: c# discord.net


【解决方案1】:

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
    };

【讨论】:

    猜你喜欢
    • 2017-03-05
    • 2022-12-11
    • 2018-05-17
    • 2022-07-10
    • 1970-01-01
    • 2022-01-23
    • 2021-01-05
    • 2020-11-04
    • 2020-11-29
    相关资源
    最近更新 更多