я хз что делать скину сразу все классы помогите прошу
public class Program
{
private DiscordSocketClient client;
private CommandService commands;
private IServiceProvider services;
public static void Main(string[] args)
=> new Program().MainAsync().GetAwaiter().GetResult();
public async Task MainAsync()
{
client = new DiscordSocketClient();
client.MessageReceived += HandleCommand;
client.Log += Log;
commands = new CommandService();
services = new ServiceCollection()
.AddSingleton(this)
.AddSingleton(client)
.AddSingleton(commands)
.AddSingleton<ConfigHandler>()
.AddSingleton<AudioService>()
.BuildServiceProvider();
await services.GetService<ConfigHandler>().PopulateConfig();
await commands.AddModulesAsync(Assembly.GetEntryAssembly(), null);
await client.LoginAsync(TokenType.Bot, services.GetService<ConfigHandler>().GetToken());
await client.StartAsync();
await Task.Delay(-1);
}
private Task Log(LogMessage msg)
{
Console.WriteLine(msg.ToString());
return Task.CompletedTask;
}
public async Task HandleCommand (SocketMessage messageParam)
{
var message = messageParam as SocketUserMessage;
if (message == null) return;
int argPos = 0;
if (!(message.HasCharPrefix('!', ref argPos) || message.HasMentionPrefix(client.CurrentUser, ref argPos))) return;
var context = new SocketCommandContext(client, message);
var result = await commands.ExecuteAsync(context, argPos, services);
if (!result.IsSuccess)
{
await context.Channel.SendMessageAsync(result.ErrorReason);
}
}
}
public class ConfigHandler
{
private Config conf;
private string configPath;
struct Config
{
public string token;
}
public ConfigHandler()
{
conf = new Config()
{
token = ""
};
}
public async Task PopulateConfig()
{
configPath = Path.Combine(Directory.GetCurrentDirectory(), "config.json ").Replace(@"\", @"\\");
Console.WriteLine(configPath);
if (!File.Exists(configPath))
{
using (StreamWriter sw = File.AppendText(configPath))
{
sw.WriteLine(JsonConvert.SerializeObject(conf));
}
Console.WriteLine("WARNING! New Config initialized! Need to fill in values before running commands!");
throw new Exception("NO CONFIG AVAILABLE! Go to executable path and fill out newly created file");
}
using (StreamReader reader = new StreamReader(configPath))
{
conf = JsonConvert.DeserializeObject<Config>(reader.ReadLine());
}
await Task.CompletedTask;
}
public string GetToken()
{
return conf.token;
}
}
public class AudioService
{
public AudioService()
{
}
public async Task<IAudioClient> ConnectAudio(SocketCommandContext context)
{
SocketGuildUser user = context.User as SocketGuildUser;
IVoiceChannel channel = user.VoiceChannel;
if (channel == null)
{
await context.Message.Channel.SendMessageAsync("User must be in a voice channel, or a voice channel must be passed as an argument.");
return null;
}
return await channel.ConnectAsync();
}
public async Task Stream(IAudioClient client, string url)
{
var ffmpeg = CreateYoutubeStream(url);
var output = ffmpeg.StandardOutput.BaseStream;
var discord = client.CreatePCMStream(AudioApplication.Mixed, 96000);
await output.CopyToAsync(discord);
await discord.FlushAsync();
}
private Process CreateYoutubeStream(string url)
{
ProcessStartInfo ffmpeg = new ProcessStartInfo
{
FileName = "cmd.exe",
Arguments = $@"/C C:\youtube-dl.exe --no-check-certificate -f bestaudio -o - {url} | ffmpeg -i pipe:0 -f s16le -ar 48000 -ac 2 pipe:1 ",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
};
return Process.Start(ffmpeg);
}
}