Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.00 KB | None | 0 0
  1.     public class AudioBot
  2.     {
  3.         public DiscordSocketClient AudioClient;
  4.         public Random RNG = new Random();
  5.         public char Prefix = '$';
  6.         public async Task MessageHandler(SocketMessage s)
  7.         {
  8.             if (s.Content.StartsWith($"{Prefix}join"))
  9.             {
  10.                 IAudioClient aic = null;
  11.                 int blockSize = 1920 * 2;
  12.                 byte[] buffer = new byte[blockSize];
  13.                 int byteCount;
  14.                 var output = new FileStream("pcm.dat", FileMode.Open, FileAccess.Read);
  15.                 if ((s.Author as IGuildUser)?.VoiceChannel == null)
  16.                     await s.Channel.SendMessageAsync("Join a voice channel first.");
  17.                 else aic = await AudioClient.Guilds.FirstOrDefault().VoiceChannels.FirstOrDefault().ConnectAsync();
  18.                 var discord = aic.CreatePCMStream(AudioApplication.Mixed, 1920 * 2);
  19.                 while (true)
  20.                 {
  21.                     byteCount = await output.ReadAsync(buffer, 0, blockSize);
  22.                     if (byteCount == 0)
  23.                         break;
  24.                     await discord.WriteAsync(buffer, 0, buffer.Length);
  25.                 }
  26.                 await discord.FlushAsync();
  27.             }
  28.         }
  29.         public async Task Start()
  30.         {
  31.             Console.ForegroundColor = ConsoleColor.Yellow;
  32.             AudioClient = new DiscordSocketClient(new DiscordSocketConfig() { WebSocketProvider = Discord.Net.Providers.WS4Net.WS4NetProvider.Instance });
  33.             await AudioClient.LoginAsync(TokenType.Bot, File.ReadAllText("t"));
  34.             AudioClient.Log += l => Console.Out.WriteLineAsync(l.ToString());
  35.             AudioClient.MessageReceived += MessageHandler;
  36.             await AudioClient.StartAsync();
  37.             await AudioClient.SetGameAsync("$join");
  38.             await Task.Delay(-1);
  39.         }
  40.     }
  41.     public class Program
  42.     {
  43.         static void Main(string[] args) => new AudioBot().Start().GetAwaiter().GetResult();
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement