{
var chanel = _client.Guilds.FirstOrDefault(g => g.Id == (v1.VoiceChannel?.Guild.Id ?? v2.VoiceChannel?.Guild.Id)).Channels.FirstOrDefault(ch => ch.Name == botChanelName) as SocketTextChannel;
if (chanel is null || user.IsBot)
return;
if (v1.VoiceChannel == null && v2.VoiceChannel != null) // connected
{
var voiceChanle = v2.VoiceChannel;
string message = "Здарова, заебал";
string url = "https://www.meme-arsenal.com/memes/96108a93bdf0e0c09be2861c87156744.jpg";
EmbedBuilder embedBuilder = new();
embedBuilder.Title = message;
embedBuilder.ImageUrl = url;
var emb = embedBuilder.Build();
//await chanel.SendMessageAsync(embed:emb);
var t = ConnectToVoice(voiceChanle, path);
//t.Wait();
}
else if(v1.VoiceChannel != null && v2.VoiceChannel == null) //disconnected
{
string message = "Пока :)";
string url = "https://www.meme-arsenal.com/memes/33dcc1a33994aa66dcaa9062b2244786.jpg";
EmbedBuilder embedBuilder = new();
embedBuilder.Title = message;
embedBuilder.ImageUrl = url;
var emb = embedBuilder.Build();
//await chanel.SendMessageAsync(embed: emb);
}
}
private static Process CreateStream(string path)
{
return Process.Start(new ProcessStartInfo
{
FileName = "ffmpeg",
Arguments = $@"-i ""{path}"" -ac 2 -f s16le -ar 48000 pipe:1",
UseShellExecute = false,
RedirectStandardOutput = true,
});
}
private static Task ConnectToVoice(SocketVoiceChannel voiceChannel, string path)
{
if (voiceChannel == null)
return Task.Delay(0);
//Console.WriteLine($"Connecting to channel {voiceChannel.Id}");
var t = Task.Run(async () =>
{
var connection = await voiceChannel.ConnectAsync().ConfigureAwait(false);
await SendAsync(connection, path).ConfigureAwait(false);
});
return t;
}
private static async Task SendAsync(IAudioClient client, string path)
{
if (client is null)
return;
// Create FFmpeg using the previous example
using (var ffmpeg = CreateStream(path))
using (var output = ffmpeg.StandardOutput.BaseStream)
using (var discord = client.CreatePCMStream(AudioApplication.Voice))
{
try { await output.CopyToAsync(discord); }
finally { await discord.FlushAsync(); }
}
}
Используй pastebin
Обсуждают сегодня