Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using Newtonsoft.Json;
- using Discord.WebSocket;
- using Discord;
- using Discord.Commands;
- using System.Diagnostics;
- using Discord.Audio;
- namespace bot_discord.modules
- {
- public class JoinAudioChannel : ModuleBase<SocketCommandContext>
- {
- public static void Events()
- {
- var handler = new CommandService();
- handler.Log += RespondToEvent;
- }
- public static Task RespondToEvent(LogMessage log)
- {
- Console.WriteLine("something happened");
- return Task.CompletedTask;
- }
- string PathTest = @"C:\Users\Matthew\Downloads\botdon rolls\bin\Debug\Winston.mp3";
- private Process CreateStream(string path)
- {
- return Process.Start(new ProcessStartInfo
- {
- FileName = "FFmpeg",
- Arguments = $"-hide_banner -loglevel panic -i \"{@"C:\Users\Matthew\Downloads\botdon rolls\bin\Debug\Winston.mp3"}\" -ac 2 -f s16le -ar 48000 pipe:1",
- UseShellExecute = false,
- RedirectStandardOutput = true,
- });
- }
- private async Task SendAsync(IAudioClient client, string path)
- {
- //path = PathTest;
- // Create FFmpeg using the previous example
- using (var FFmpeg = CreateStream(@"C:\Users\Matthew\Downloads\botdon rolls\bin\Debug\Winston.mp3"))
- using (var output = FFmpeg.StandardOutput.BaseStream)
- using (var discord = client.CreatePCMStream(AudioApplication.Mixed))
- {
- try { await output.CopyToAsync(discord); }
- finally { await discord.FlushAsync(); }
- }
- }
- [Command ("join", RunMode = RunMode.Async)]
- public async Task join(IVoiceChannel channel = null)
- {
- channel = (Context.User as IGuildUser)?.VoiceChannel;
- if (channel == null)
- {
- await Context.Channel.SendMessageAsync("you must be in a voice channel to summon bot");
- return;
- }
- var audioclient = await channel.ConnectAsync();
- await SendAsync(audioclient, PathTest);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement