This commit is contained in:
2022-04-09 10:18:39 +03:00
parent 3d4c9ae9ea
commit 1e7387cfa7
11 changed files with 186 additions and 15 deletions

View File

@@ -3,6 +3,8 @@ using Discord.Audio;
using Discord.Commands;
using Discord.WebSocket;
using MusicCommands;
using PluginManager.Interfaces;
using PluginManager.Others;
@@ -37,22 +39,20 @@ namespace CMD_Utils.Music
return;
}
// Get the audio channel
Data.voiceChannel = (context.User as IGuildUser)?.VoiceChannel;
if (Data.voiceChannel == null) { await context.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument."); return; }
// For the next step with transmitting audio, you would want to pass this Audio Client in to a service.
Data.audioClient = await Data.voiceChannel.ConnectAsync();
// Create FFmpeg using the previous example
using (var ffmpeg = CreateStream(path))
using (var output = ffmpeg.StandardOutput.BaseStream)
using (var discord = Data.audioClient.CreatePCMStream(AudioApplication.Mixed))
{
try { await output.CopyToAsync(discord); }
finally { await discord.FlushAsync(); }
if (Data.CurrentlyRunning != null)
Data.CurrentlyRunning.Stop();
Data.CurrentlyRunning = new MusicPlayer(output, discord);
await Data.CurrentlyRunning.StartSendAudio();
}
}