Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AudioBot
- {
- public DiscordSocketClient AudioClient;
- public Random RNG = new Random();
- public char Prefix = '$';
- public async Task MessageHandler(SocketMessage s)
- {
- if (s.Content.StartsWith($"{Prefix}join"))
- {
- IAudioClient aic = null;
- int blockSize = 1920 * 2;
- byte[] buffer = new byte[blockSize];
- int byteCount;
- var output = new FileStream("pcm.dat", FileMode.Open, FileAccess.Read);
- if ((s.Author as IGuildUser)?.VoiceChannel == null)
- await s.Channel.SendMessageAsync("Join a voice channel first.");
- else aic = await AudioClient.Guilds.FirstOrDefault().VoiceChannels.FirstOrDefault().ConnectAsync();
- var discord = aic.CreatePCMStream(AudioApplication.Mixed, 1920 * 2);
- while (true)
- {
- byteCount = await output.ReadAsync(buffer, 0, blockSize);
- if (byteCount == 0)
- break;
- await discord.WriteAsync(buffer, 0, buffer.Length);
- }
- await discord.FlushAsync();
- }
- }
- public async Task Start()
- {
- Console.ForegroundColor = ConsoleColor.Yellow;
- AudioClient = new DiscordSocketClient(new DiscordSocketConfig() { WebSocketProvider = Discord.Net.Providers.WS4Net.WS4NetProvider.Instance });
- await AudioClient.LoginAsync(TokenType.Bot, File.ReadAllText("t"));
- AudioClient.Log += l => Console.Out.WriteLineAsync(l.ToString());
- AudioClient.MessageReceived += MessageHandler;
- await AudioClient.StartAsync();
- await AudioClient.SetGameAsync("$join");
- await Task.Delay(-1);
- }
- }
- public class Program
- {
- static void Main(string[] args) => new AudioBot().Start().GetAwaiter().GetResult();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement