/// <summary> /// Starts the <see cref="CoinBot" />. /// </summary> /// <param name="provider">The <see cref="IServiceProvider" />.</param> /// <returns></returns> private static async Task RunAsync(IServiceProvider provider) { ILoggerFactory loggerFactory = provider.GetRequiredService <ILoggerFactory>(); loggerFactory.AddSerilog(); //set up a task completion source so we can quit on CTRL+C TaskCompletionSource <bool> exitSource = new TaskCompletionSource <bool>(); Console.CancelKeyPress += (sender, eventArgs) => { eventArgs.Cancel = true; exitSource.SetResult(result: true); }; await provider.AddCommandsAsync(); MarketManager marketManager = provider.GetRequiredService <MarketManager>(); DiscordBot bot = provider.GetRequiredService <DiscordBot>(); // Initialize the bot DiscordBotSettings botConfig = provider.GetRequiredService <IOptions <DiscordBotSettings> >() .Value; await bot.LoginAsync(tokenType : TokenType.Bot, token : botConfig.Token); // Start the bot & coinSource await bot.StartAsync(); marketManager.Start(); // Keep the application alive until the exitSource task is completed. await exitSource.Task; // Stop the bot & coinSource await bot.LogoutAsync(); marketManager.Stop(); }