Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.IO;
  7. using Newtonsoft.Json;
  8. using Discord.WebSocket;
  9. using Discord;
  10. using Discord.Commands;
  11. using System.Diagnostics;
  12. using Discord.Audio;
  13.  
  14. namespace bot_discord.modules
  15. {
  16. public class JoinAudioChannel : ModuleBase<SocketCommandContext>
  17. {
  18. public static void Events()
  19. {
  20. var handler = new CommandService();
  21. handler.Log += RespondToEvent;
  22. }
  23. public static Task RespondToEvent(LogMessage log)
  24. {
  25. Console.WriteLine("something happened");
  26. return Task.CompletedTask;
  27. }
  28. string PathTest = @"C:\Users\Matthew\Downloads\botdon rolls\bin\Debug\Winston.mp3";
  29. private Process CreateStream(string path)
  30. {
  31. return Process.Start(new ProcessStartInfo
  32. {
  33. FileName = "FFmpeg",
  34. Arguments = $"-hide_banner -loglevel panic -i \"{@"C:\Users\Matthew\Downloads\botdon rolls\bin\Debug\Winston.mp3"}\" -ac 2 -f s16le -ar 48000 pipe:1",
  35. UseShellExecute = false,
  36. RedirectStandardOutput = true,
  37. });
  38. }
  39. private async Task SendAsync(IAudioClient client, string path)
  40. {
  41. //path = PathTest;
  42. // Create FFmpeg using the previous example
  43. using (var FFmpeg = CreateStream(@"C:\Users\Matthew\Downloads\botdon rolls\bin\Debug\Winston.mp3"))
  44. using (var output = FFmpeg.StandardOutput.BaseStream)
  45. using (var discord = client.CreatePCMStream(AudioApplication.Mixed))
  46. {
  47. try { await output.CopyToAsync(discord); }
  48. finally { await discord.FlushAsync(); }
  49. }
  50. }
  51. [Command ("join", RunMode = RunMode.Async)]
  52. public async Task join(IVoiceChannel channel = null)
  53. {
  54. channel = (Context.User as IGuildUser)?.VoiceChannel;
  55.  
  56. if (channel == null)
  57. {
  58. await Context.Channel.SendMessageAsync("you must be in a voice channel to summon bot");
  59. return;
  60. }
  61. var audioclient = await channel.ConnectAsync();
  62. await SendAsync(audioclient, PathTest);
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement