尝试通过语音通道播放 youtube 音频时,C# discord bot 未知操作码 8
C# discord bot unknown opcode 8 when attempting to play youtube audio through voice channel
我目前正在开发 C# discord.net 1.0.0 discord 机器人,我试图添加一个命令,允许机器人通过语音聊天播放 youtube 音频,但是,当机器人加入时语音聊天并尝试播放音频,我的控制台只是 returns :
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);
}
}
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
};
我目前正在开发 C# discord.net 1.0.0 discord 机器人,我试图添加一个命令,允许机器人通过语音聊天播放 youtube 音频,但是,当机器人加入时语音聊天并尝试播放音频,我的控制台只是 returns :
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);
}
}
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
};