public async Task Start() { // Define the DiscordSocketClient client = new DiscordSocketClient(); client.Log += (x => { Console.ForegroundColor = ConsoleColor.Gray; Console.Write($"[{DateTime.Now.GetDateTimeFormats()[110]}]"); switch ((int)x.Severity) { case 0: Console.ForegroundColor = ConsoleColor.Red; break; case 1: Console.ForegroundColor = ConsoleColor.Red; break; case 2: Console.ForegroundColor = ConsoleColor.DarkYellow; break; case 3: Console.ForegroundColor = ConsoleColor.Yellow; break; case 4: Console.ForegroundColor = ConsoleColor.Magenta; break; case 5: Console.ForegroundColor = ConsoleColor.DarkMagenta; break; default: Console.ForegroundColor = ConsoleColor.White; break; } //sets color according to severity Console.WriteLine(x.Message); return(Task.CompletedTask); }); var token = File.ReadAllText("token.txt"); // Login and connect to Discord. await client.LoginAsync(TokenType.Bot, token); await client.StartAsync(); var map = new DependencyMap(); map.Add(client); handler = new CommandHandler(); await handler.Install(map); client.Ready += Client_Ready; Task Client_Ready() { client.SetStatusAsync(UserStatus.Online); client.SetGameAsync("Type >help!"); return(Task.CompletedTask); } // Block this program until it is closed. client.LeftGuild += x => { int count = int.Parse(File.ReadAllText("servercount.dat")); count--; File.WriteAllText("servercount.dat", count.ToString()); return(Task.CompletedTask); }; client.JoinedGuild += (async x => { await x.DefaultChannel.SendMessageAsync($"Hello I am {client.CurrentUser.Username} 😄.\rI am currently in early development so please report any problems to @Ariss#4202.\rType >help to get started!"); int count = int.Parse(File.ReadAllText("servercount.dat")); count++; File.WriteAllText("servercount.dat", count.ToString()); var g = x as IGuild; var channels = await g.GetChannelsAsync(); GuildPermissions perms = GuildPermissions.None; perms = g.EveryoneRole.Permissions.Modify(sendMessages: false); Dictionary <string, ulong> roledict = g.Roles.ToDictionary(a => { return(a.Name); }, y => { return(y.Id); }); IRole muteRole = null; if (roledict.ContainsKey("Muted") == false) { muteRole = await g.CreateRoleAsync("Muted", perms, new Color(50, 50, 50), true); } else { roledict.TryGetValue("Muted", out ulong id); muteRole = g.GetRole(id); } OverwritePermissions per = new OverwritePermissions(); per = OverwritePermissions.InheritAll.Modify(sendMessages: PermValue.Deny); foreach (IGuildChannel chan in channels) { await chan.AddPermissionOverwriteAsync(muteRole, per); } }); await GetInput(); await Task.Delay(-1); }