public async Task SetGame([Summary("The game for the bot to play")][Remainder] string game) { await Context.Channel.TriggerTypingAsync(); _logger.LogInformation("{username}#{discriminator} invoked game ({game}) on {server}/{channel}", Context.User.Username, Context.User.Discriminator, game, Context.Guild?.Name ?? "DM", Context.Channel.Name); if (Context.User.Username != _settings.OwnerName || Context.User.Discriminator != _settings.OwnerDiscriminator) { await ReplyAsync("Sorry, only the bot's owner can set the game!"); } else { var settings = await _discordBotSettingsRepository.Get(); await _client.SetGameAsync(game); settings.Game = game; await _discordBotSettingsRepository.EditAsync(settings); await ReplyAsync("Game changed!"); await _servers.SendLogsAsync(Context.Guild, "Game Updated", $"{Context.User.Mention} has changed the game to {game}."); } }
public async Task Start() { try { ShowJoinAndPartMessages = bool.Parse(_configuration.GetSection("ShowBotJoinMessages").Value); } catch (Exception ex) { _logger.LogWarning(ex, "Failed to parse ShowBotJoinMessages. Using false."); ShowJoinAndPartMessages = false; } var settings = await _discordBotSettingsRepository.Get(); if (settings == null) { settings = GetTokenFromConsole(); } try { await _client.LoginAsync(TokenType.Bot, settings.Token); } catch (Discord.Net.HttpException ex) { if (ex.Reason == "401: Unauthorized") { _logger.LogCritical("Token is not correct!"); Console.WriteLine("\nToken is incorrect."); Console.Write("Enter Token: "); settings.Token = Console.ReadLine(); await _discordBotSettingsRepository.EditAsync(settings); Start(); } else { _logger.LogCritical(ex, "An unhandeled HttpException has occured!"); Console.WriteLine("An unhandeled HttpException has occured!"); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.WriteLine("Discord Bot is quiting!"); if (LavaLinkHelper.isLavaLinkRunning()) { LavaLinkHelper.StopLavaLink(); } Environment.Exit(0); } } await _client.StartAsync(); await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _serviceProvider); }