public async Task StartAsync() { Client = new DiscordSocketClient(new DiscordSocketConfig() { LogLevel = LogSeverity.Verbose, // Specify console verbose information level. MessageCacheSize = 10000, AlwaysDownloadUsers = true, // Tell discord.net how long to store messages (per channel). }); Client.Log += (Log) => Task.Run(() => Logger.Log(Enums.LogType.Info, Enums.LogSource.Client, Log.Message)); GuildHandler.GuildConfigs = await GuildHandler.LoadServerConfigsAsync <GuildModel>(); await Client.LoginAsync(TokenType.Bot, Config.Load().Token); await Client.StartAsync(); var serviceProvider = ConfigureServices(); Handler = new CommandHandler(serviceProvider); await Handler.ConfigureAsync(); await Task.Delay(-1); // Prevent the console window from closing. }
public async Task MainAsync() { _client = new DiscordSocketClient(); var services = ConfigureServices(); services.GetRequiredService <LogService>(); await services.GetRequiredService <CommandHandlingService>().InitializeAsync(services); try { Config.Load(); GuildHandler.GuildConfigs = await GuildHandler.LoadServerConfigsAsync <GuildModel>(); await _client.LoginAsync(TokenType.Bot, Config.Load().Token); await _client.StartAsync(); } catch (HttpException httpException) { if (httpException.HttpCode == HttpStatusCode.Unauthorized) { Config.NewToken(); await _client.LoginAsync(TokenType.Bot, Config.Load().Token); await _client.StartAsync(); } } await Task.Delay(-1); }
public static async Task Main() { _config = new DiscordSocketConfig { LogLevel = LogSeverity.Info, AlwaysDownloadUsers = true, MessageCacheSize = 250, TotalShards = 1 }; _client = new DiscordShardedClient(_config); _command = new CommandHandler(); ConfigHandler.DirectoryCheck(); ConfigHandler.Config = await ConfigHandler.LoadConfigAsync(); GuildHandler.GuildConfigs = await GuildHandler.LoadServerConfigsAsync <GuildModel>(); BlacklistHandler.BlacklistConfigs = await BlacklistHandler.LoadBlacklistAsync <BlacklistModel>(); string token; switch (ConfigHandler.Config.ReleaseEnv) { case "dev": case "development": token = ConfigHandler.Config.DevToken; break; case "prod": case "production": token = ConfigHandler.Config.Token; break; default: Console.WriteLine("ReleaseEnv can only be production or development"); Environment.Exit(0); return; } await _client.LoginAsync(TokenType.Bot, token); await _client.StartAsync(); foreach (var shard in _client.Shards) { shard.Ready += async() => await shard.SetGameAsync(PlayingStatus.Replace("{username}", shard.CurrentUser.Username)); } _client.UserJoined += Events.UserJoinedAsync; _client.UserLeft += Events.UserLeftAsync; _client.GuildAvailable += Events.HandleGuildConfigAsync; _client.LeftGuild += async guild => await Events.LeftGuildAsync(guild); _client.JoinedGuild += async guild => await Events.JoinedGuildAsync(guild); _client.UserBanned += Events.BannedUserAsync; await _command.Install(_client); _client.Log += Log; if (ConsolePresent) { var cki = Console.ReadKey(true); if (cki.Key == ConsoleKey.Escape || cki.Key == ConsoleKey.X) { await _client.SetGameAsync(""); await _client.SetStatusAsync(UserStatus.Invisible); await _client.LogoutAsync(); await _client.StopAsync(); Environment.Exit(0); } } await Task.Delay(-1); }