using Discord; using Discord.Commands; using Discord.WebSocket; using Kasbot.Services; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using TextCommandFramework.Services; namespace TextCommandFramework { class Program { static void Main(string[] args) { new Program().MainAsync().GetAwaiter().GetResult(); } public async Task MainAsync() { using (var services = ConfigureServices()) { var token = Environment.GetEnvironmentVariable("TOKEN"); if (token == null) { throw new Exception("Discord Bot Token was not found."); } var client = services.GetRequiredService(); client.Log += LogAsync; services.GetRequiredService().Log += LogAsync; await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); await services.GetRequiredService().InitializeAsync(); await Task.Delay(Timeout.Infinite); } } private Task LogAsync(LogMessage log) { Console.WriteLine(log.ToString()); return Task.CompletedTask; } private ServiceProvider ConfigureServices() { return new ServiceCollection() .AddSingleton(new DiscordSocketConfig { GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent }) .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .BuildServiceProvider(); } } }