public async Task ExcludeChannel(CommandContext ctx, string command, params DiscordChannel[] channels) { if (await Permissions.HandlePermissionsCheck(ctx)) { Func <DiscordChannel, bool> commandsAction; string verb; string verb2; switch (command) { case "add": commandsAction = delegate(DiscordChannel c) { ulong id = c.Id; // Make sure it doesn't exist. bool notExists_returnVal = !Program.Settings.ExcludedChannels.Contains(id); // It doesn't exist, so we can add it. if (notExists_returnVal) { Program.Settings.ExcludedChannels.Add(id); } return(notExists_returnVal); }; verb = @"add"; verb2 = @"added"; break; case "remove": commandsAction = delegate(DiscordChannel c) { ulong id = c.Id; // Check if it exists. bool exists_returnVal = Program.Settings.ExcludedChannels.Contains(id); // Only remove it if it exists. if (exists_returnVal) { Program.Settings.ExcludedChannels.Remove(id); } return(exists_returnVal); }; verb = @"remove"; verb2 = @"removed"; break; default: commandsAction = null; verb = String.Empty; verb2 = String.Empty; break; } // Check if we got a valid command arg. if (commandsAction is null) { // We did not get a valid command arg. await GenericResponses.HandleInvalidArguments(ctx); } else { // We did get a valid command arg. // Array of everything and a description of if it was added or not. Dictionary <DiscordChannel, bool> successAdded = new Dictionary <DiscordChannel, bool>(channels.Length); // Loop through each channel. foreach (DiscordChannel chan in channels) { // Invoke our command on each channel successAdded.Add(chan, commandsAction.Invoke(chan)); } // Check if anything was added successfully. if (successAdded.Any(a => a.Value)) { // Yes, at least one thing was added successfully. So let's save the settings now that they've been updated. Program.SaveSettings(); } // Respond. await GenericResponses.SendMessageChangedNotChanged( channel : ctx.Channel, title : $"Attempted to {verb} channel(s)", mention : ctx.Member.Mention, body : $"I attempted to {verb} the channels you gave me.", successChanged : successAdded, verb : verb2, invertedVerb : $"not {verb2}"); } } }